PyGObject on Windows
Asked Answered
U

3

10

Over the last few days of headaches, I've found 3 possible methods to do this, all of which have issues.

  • PyGObject's pip install fails due to a lack of Cairo and probably other dependencies. While this would be my preferred method, it would probably be the hardest to fulfill.

  • Using MSYS2 allows me to use GObject through the mingw64 python, but using pip to get my other modulues such as pylint fails. I'd like to have an MSYS2 or similar install on my system anyways to make some windows binaries, so I'm very open to this as well.

    • EDIT: Got pip to work in MSYS2. Make sure to sync toolchain with pacman.
  • PyGObject for Windows seems messy at best and isn't up-to-date. Would require having a second python installation anyways, giving no benefit over MSYS2.

Note I'm a complete newbie to Unix and have little experience with CLI's in general, so any help regarding MSYS2 will need to be explained as if to a child. My only other experience with this stuff involved an endless cycle of hell that was installing Arch to a separate partition, breaking said install, then reinstalling again.

I also tried Cygwin, but I couldn't get that to run Python with GObject at all with my "install all the needed packages then pray" method. Creating a Gtk.Window() caused the terminal to use none of the memory it had and explode.

Urogenital answered 12/1, 2018 at 1:32 Comment(1)
Take a look at this article blogs.gnome.org/kittykat/2014/01/29/… It explains how to install PyGObject, it works for me...Odalisque
P
7

MSYS2 is currently the only "officially" supported way: https://pygobject.readthedocs.io/en/latest/getting_started.html#windows

pip in MSYS2 should work in general, if something doesn't please file a bug at https://github.com/Alexpux/MINGW-packages/issues .

Politician answered 12/1, 2018 at 9:43 Comment(1)
I've tried my best to replicate what Quodlibet has achieved for Windows, but it seems a road full of traps. We really need a functional and replicable pipeline, i.e., from a .py to an installer that installs a software package with native executables.Clench
I
0

As you said in the third alternative to install a new Python version, you can create and run multiple Python versions using pyenv. You can go through the installation section of their Github repo for installation and an overview: https://github.com/pyenv/pyenv/

For a comprehensive guide on how to use it, you read this amazing post by Real Python: https://realpython.com/intro-to-pyenv/

Inexperienced answered 24/4, 2021 at 0:15 Comment(0)
N
0

I also want to leave the info here how this works, because during my research this thread came also up often. You have to compile PyGObject yourself, but you get help from a script.

You still need MSYS2 to support the compile process, go to http://www.msys2.org/ and download the x86_64 installer. Follow the instructions on the page for setting up the basic environment.

You ned a C++ compiler, therefore install Visual Studio Community Edition with the C++ desktop development workload.

Then add the future GTK folder to Your Environmental Variables: Type environement with the windows start menu open and click “Edit environment variables for your account”. Double-click the Path row in the top list of variables. Click “New” to add a new item to the list. Paste in C:\gtk-build\gtk\x64\release\bin . Click "OK" twice.

Clone [gsvbuild] (scripts for GTK compilation). Open a powershell prompt as administrator and enter the following commands.

mkdir C:\gtk-build\github
cd C:\gtk-build\github
git clone C:\github.com\wingtk\gvsbuild
cd *your project dir*
python -m venv .venv
.\.venv\Scripts\activate.ps1
pip install .
gvsbuild build --enable-gi --py-wheel gobject-introspection gtk3 pycairo pygobject

Once that builds, you can switch to your project you are trying to use PyGObject for and activate the virtualenv. Then install the wheels you created above:

Get-ChildItem C:\gtk-build\build\x64\release\*\dist\*.whl | ForEach-Object -process { poetry run pip install $_ }

More details in this thread: File msvc_recommended_pragmas.h missing while installing PyGObject via pip

Nogood answered 3/12, 2023 at 9:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.