如何安装 PyGObject? [英] How do I install PyGObject?

查看:102
本文介绍了如何安装 PyGObject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows 7 上为 Python 2.7 安装 PyGtk,但是当去使用 pip 安装 PyGtk 时,它说我需要 PyGObject(Go 图)所以我安装了用于 Python 的 Visual C++ 包(我知道我有正确的版本)并尝试使用 pip 安装 PyGObject,但它不断出现错误消息,指出 cairo.h 丢失,果然我检查了目录,但它不存在.我到底应该如何安装 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. How on earth am I supposed to install PyGObject?

推荐答案

还有很长的路要走,需要在这里和那里进行一些调整,但它确实有效.我用的是Python 3.6,不知道2.7能不能用.

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.

首先,从这里获取 GTK+3 for Windows 的构建脚本 (https://github.com/guruDanny67/gvsbuild).这是这个 repo 的一个分支(https://github.com/wingtk/gvsbuild),但它似乎与各种版本的软件包更新.我使用了 'ed2018' 分支,它似乎是最相关的,但是来自该分支的更改可能会以 'master' 结尾,因此请检查前后提交的数量.

First, get build scripts for GTK+3 for Windows from here (https://github.com/guruDanny67/gvsbuild). 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. 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.

如果您没有在 Visual Studio 2017 中安装 C++ 工作负载,您还需要一个 Visual Studio 2017 构建工具.您也可以使用 VS 2015,但我没有尝试.2017 构建工具在这里:https://visualstudio.microsoft.com/downloads/#other.您可能还应该包括VC++ 2015.3 v14.00 桌面工具集".

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. 2017 Build tools are here: https://visualstudio.microsoft.com/downloads/#other. You should probably also include 'VC++ 2015.3 v14.00 toolset for desktop'.

您需要安装 Python.我用的是3.6版本,其他的不知道.

You'll need a Python installed. I used version 3.6, don't know about the others.

此外,您还需要 MSYS2(http://www.msys2.org/).它只用于一些需要的工具.

Also, you'll need MSYS2 (http://www.msys2.org/). It's only used for some needed tools.

编译/安装(大部分)非常简单,但需要一些时间(SSD 可能有很大帮助).只需阅读 gvsbuild 页面上的说明.如果您逐个构建,在命令行中包含 --fast-build 参数会有所帮助.

The compiling/installation is (mostly) quite straightforward, but it takes some time (SSD probably helps a lot). Just read the instructions on the gvsbuild page. If you build piece by piece, it helps to include --fast-build parameter in the command line.

您可以获得所有可以使用

You can get the list of all projects than can be build using

python build.py list

或者干脆

build list

如果您安装了 Python 启动器.

if you have a Python launcher installed.

构建的所有选项:

build build --help

有一个用于 pygobject 和 pycairo 的构建项目,它将它们安装在已安装的 Python site-packages 目录中.然而,更好的方法是卸载它们(使用 pip 或者如果 pip 抱怨就删除目录).

There's a build project for a pygobject and pycairo, which installs them in the installed Python site-packages directory. However, the better way is to uninstall them (use pip or just remove directories if pip complains).

然后,从 PyPi 站点 (https://pypi.org) 下载 PyCairo 和 PyGObject 的源代码/project/pycairo/, https://pypi.org/project/PyGObject/).将带有一堆 lib 文件的目录添加到您的 LIB 环境变量中(应该类似于 f:\gtk-build\gtk\Win32\release\lib).将包含目录添加到您的 INCLUDE 环境变量 (c:\gtk-build\gtk\Win32\release\include),然后运行 ​​setup build 脚本首先用于开罗.如果构建完成正常,运行 setup bdist_wininst.它将在 dist 子目录中生成一个安装 exe 文件.运行这个 exe(以管理员身份),你应该已经安装了 PyCairo.

Then, download the sources for the PyCairo and PyGObject from the PyPi site (https://pypi.org/project/pycairo/, https://pypi.org/project/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). 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. If build finished OK, run setup bdist_wininst. It will generate an installation exe file in the dist subdirectory. Run this exe (as an administrator), and you should have PyCairo installed.

PyGobject 的构建是相同的.

The build for the PyGobject is the same.

如果 setup build 抱怨它找不到某些 .lib.include 文件,只需在某处找到它们所在的文件夹在您的 gtk-build\gtk\Win32\release\' 文件夹中.将该文件夹包含在LIBINCLUDE`变量中并再次运行.

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 inLIBorINCLUDE` variable and run again.

HTH,汤姆

这篇关于如何安装 PyGObject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆