简体   繁体   English

如何安装 PyGObject?

[英]How do I install PyGObject?

I am trying to install PyGtk on windows 7 for Python 2.7, but when go to use pip to install PyGtk it says i need PyGObject (Go figure) so I installed the Visual C++ package for Python (I know I have the correct version) and tried using pip to install PyGObject but it keeps comming out with an error message saying that cairo.h is missing, and sure enough I check in the directory and it wasn't there.我正在尝试在 Windows 7 上为 Python 2.7 安装 PyGtk,但是当去使用 pip 安装 PyGtk 时,它说我需要 PyGObject(Go 图)所以我安装了 Python 的 Visual C++ 包(我知道我有正确的版本)和尝试使用 pip 安装 PyGObject,但它不断出现错误消息,指出 cairo.h 丢失,果然我检查了目录,但它不存在。 How on earth am I supposed to install PyGObject?我到底应该如何安装 PyGObject?

错误信息

There's a quite long way, and it needs some tweaking here and there, but it works.有很长的路要走,需要在这里和那里进行一些调整,但它确实有效。 I used Python 3.6, and don't know whether it will work in 2.7.我用的是Python 3.6,不知道2.7能不能用。

First, get build scripts for GTK+3 for Windows from here ( https://github.com/guruDanny67/gvsbuild ).首先,从这里 ( https://github.com/guruDanny67/gvsbuild ) 获取 Windows 版 GTK+3 的构建脚本。 It's a fork from this repo ( https://github.com/wingtk/gvsbuild ), but it seems to be more up-to-date with the various versions of packages.它是这个 repo ( https://github.com/wingtk/gvsbuild ) 的一个分支,但它似乎与各种版本的软件包更新。 I used the 'ed2018' branch, which seems to be the most relevant, but the changes from this branch will probably end in 'master', so check the number of commits ahead and behind.我使用了 'ed2018' 分支,它似乎是最相关的,但是来自该分支的更改可能会以 'master' 结尾,因此请检查前后提交的数量。

You will also need a Visual Studio 2017 build tools if you don't have C++ workload installed in Visual Studio 2017. You can also use VS 2015, but I didn't try it.如果您没有在 Visual Studio 2017 中安装 C++ 工作负载,您还需要一个 Visual Studio 2017 构建工具。您也可以使用 VS 2015,但我没有尝试。 2017 Build tools are here: https://visualstudio.microsoft.com/downloads/#other . 2017 构建工具在这里: https : //visualstudio.microsoft.com/downloads/#other You should probably also include 'VC++ 2015.3 v14.00 toolset for desktop'.您可能还应该包括“VC++ 2015.3 v14.00 桌面工具集”。

You'll need a Python installed.您需要安装 Python。 I used version 3.6, don't know about the others.我用的是3.6版,不知道其他的。

Also, you'll need MSYS2 ( http://www.msys2.org/ ).此外,您还需要 MSYS2 ( http://www.msys2.org/ )。 It's only used for some needed tools.它仅用于一些需要的工具。

The compiling/installation is (mostly) quite straightforward, but it takes some time (SSD probably helps a lot).编译/安装(大部分)非常简单,但需要一些时间(SSD 可能有很大帮助)。 Just read the instructions on the gvsbuild page.只需阅读 gvsbuild 页面上的说明。 If you build piece by piece, it helps to include --fast-build parameter in the command line.如果您--fast-build ,在命令行中包含--fast-build参数会--fast-build帮助。

You can get the list of all projects than can be build using您可以获得所有项目的列表,而不是可以使用

python build.py list

or simply或者干脆

build list

if you have a Python launcher installed.如果您安装了 Python 启动器。

All the options for build:构建的所有选项:

build build --help

There's a build project for a pygobject and pycairo, which installs them in the installed Python site-packages directory.有一个 pygobject 和 pycairo 的构建项目,它将它们安装在已安装的 Python site-packages目录中。 However, the better way is to uninstall them (use pip or just remove directories if pip complains).但是,更好的方法是卸载它们(使用pip或如果 pip 抱怨则删除目录)。

Then, download the sources for the PyCairo and PyGObject from the PyPi site ( https://pypi.org/project/pycairo/ , https://pypi.org/project/PyGObject/ ).然后,从 PyPi 站点 ( https://pypi.org/project/pycairo/https://pypi.org/project/PyGObject/ ) 下载 PyCairo 和 PyGObject 的源代码。 Add the directory with the bunch of lib files to your LIB environment variable (should be something like f:\\gtk-build\\gtk\\Win32\\release\\lib ).将包含一堆lib文件的目录添加到您的LIB环境变量中(应该类似于f:\\gtk-build\\gtk\\Win32\\release\\lib )。 Add the include directory to your INCLUDE environment variable ( c:\\gtk-build\\gtk\\Win32\\release\\include ), and run the setup build script for the Cairo first.将包含目录添加到您的INCLUDE环境变量 ( c:\\gtk-build\\gtk\\Win32\\release\\include ),并首先运行 Cairo 的setup build脚本。 If build finished OK, run setup bdist_wininst .如果构建完成正常,运行setup bdist_wininst It will generate an installation exe file in the dist subdirectory.它将在dist子目录中生成一个安装 exe 文件。 Run this exe (as an administrator), and you should have PyCairo installed.运行这个 exe(以管理员身份),你应该已经安装了 PyCairo。

The build for the PyGobject is the same. PyGobject 的构建是相同的。

If the setup build complains that it cannot find some .lib or .include file, just find which folder are they in, somewhere in your gtk-build\\gtk\\Win32\\release\\' folder. Include that folder in如果setup build抱怨它找不到某些.lib.include文件,只需在gtk-build\\gtk\\Win32\\release\\' folder. Include that folder in某处找到它们在哪个文件gtk-build\\gtk\\Win32\\release\\' folder. Include that folder in gtk-build\\gtk\\Win32\\release\\' folder. Include that folder in LIB or INCLUDE` variable and run again. gtk-build\\gtk\\Win32\\release\\' folder. Include that folder in LIB or INCLUDE` 变量中并再次运行。

HTH, Tom HTH,汤姆

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM