How do I install PyGObject?

无人久伴 提交于 2021-02-07 09:47:14

问题


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?

Error Message


回答1:


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.

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.

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'.

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

Also, you'll need 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). 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

or simply

build list

if you have a Python launcher installed.

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. However, the better way is to uninstall them (use pip or just remove directories if pip complains).

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.

The build for the PyGobject is the same.

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, Tom




回答2:


Installation of PyGObject

Windows OS

  1. Go to http://www.msys2.org/ and download the x86_64 installer

  2. Follow the instructions on the page for setting up the basic environment

  3. Run C:\msys64\mingw64.exe - a terminal window should pop up

  4. Execute pacman -Suy

  5. Execute pacman -S mingw-w64-x86_64-gtk3 mingw-w64-x86_64-python3 mingw-w64-x86_64-python3-gobject

  6. To test that GTK 3 is working you can run gtk3-demo

  7. Copy the hello.py script (given below) to C:\msys64\home\<username>

  8. In the mingw64 terminal execute python3 hello.py- a window should appear.

  9. You can install pip using following in the mingw64 terminal window:

pacman -S python3-pip

pip3 install --upgrade pip

hello.py

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

window = Gtk.Window(title="Hello World")
window.show()
window.connect("destroy", Gtk.main_quit)
Gtk.main()


来源:https://stackoverflow.com/questions/51485852/how-do-i-install-pygobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!