File msvc_recommended_pragmas.h missing while installing PyGObject via pip
Asked Answered
P

2

12

I tried to install PyGObject via pip and it fails with given error:

Building wheels for collected packages: pygobject
Building wheel for pygobject (PEP 517) ... error
ERROR: Command errored out with exit status 1:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DPY_SSIZE_T_CLEAN -IC:\Users\James\AppData\Local\Temp\pip-install-deoh1xpv\pygobject_2e13db219b124bfd8bf7a88e47dc19a5 -IC:\Users\James\AppData\Local\Temp\pip-install-deoh1xpv\pygobject_2e13db219b124bfd8bf7a88e47dc19a5\gi -IC:\Program Files\Python39\include -IC:\Program Files\Python39\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\ATLMFC\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt /Tcgi\gimodule.c /Fobuild\temp.win-amd64-3.9\Release\gi\gimodule.obj -FImsvc_recommended_pragmas.h
gimodule.c
gi\gimodule.c: fatal error C1083: Cannot open include file: 'msvc_recommended_pragmas.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual
Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
----------------------------------------
ERROR: Failed building wheel for pygobject

I had another attempt with python -m pip install pygobject --no-use-517 and it still fails with error:

Building wheels for collected packages: pygobject
Building wheel for pygobject (setup.py) ... error
ERROR: Command errored out with exit status 1:

gimodule.c
gi\gimodule.c: fatal error C1083: Cannot open include file: 'msvc_recommended_pragmas.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
----------------------------------------
ERROR: Failed building wheel for pygobject
Running setup.py clean for pygobject
Failed to build pygobject

Installing collected packages: pygobject
Running setup.py install for pygobject ... error
ERROR: Command errored out with exit status 1:

gimodule.c
gi\gimodule.c: fatal error C1083: Cannot open include file: 'msvc_recommended_pragmas.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
----------------------------------------
ERROR: Command errored out with exit status 1: 

'C:\Program Files\Python39\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\James\\AppData\\Local\\Temp\\pip-install-x0ki7wgt\\pygobject_0af3e48dd4b543de8f83ff716124e468\\setup.py'"'"'; __file__='"'"'C:\\Users\\James\\AppData\\Local\\Temp\\pip-install-x0ki7wgt\\pygobject_0af3e48dd4b543de8f83ff716124e468\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\James\AppData\Local\Temp\pip-record-andppe11\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Program Files\Python39\Include\pygobject' Check the logs for full command output.

It seems like all fails is due to a missing file msvc_recommended_pragmas.h. This leaves me with no clue of what I may have missed. All runtime dependencies involved (python3.9, pip, MSYS2, C++ Build Tools from Visual Studio) have been upgraded to the latest version FYI.

Practice answered 21/1, 2021 at 15:16 Comment(1)
Please try msys as: https://mcmap.net/q/1011774/-how-do-i-install-pygobject/…Novosibirsk
S
5

gvsbuild provides a method to compile GTK in Windows. The latest instructions can be found in the README at https://github.com/wingtk/gvsbuild. Once you install the dependencies, it will work something like this:

mkdir C:\gtk-build\github
cd C:\gtk-build\github
git clone C:\github.com\wingtk\gvsbuild
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 $_ }
Sniper answered 24/6, 2022 at 0:4 Comment(2)
Word of caution: gvsbuild targets GLib 2.72 whereas the GStreamer runtime is built with 2.62, which may cause linking oddities and dependency issues at runtime. I also had to define g_memdup2 inside gobject-introspection as it seemed to be missing/not exported from glib2.0.dllDiorite
You can build gstreamer with gvsbuild as well with gvsbuild build gstreamer.Sniper
D
1

I stumbled over this today as I was trying to setup up my Visual Studio Code project also under windows, coming from a Raspberry OS.

This was the crucial hint to get PYGObject work under windows in a windoes Python environment and not in the msys2 environment. As it took me some hours, I will also add my full solution here, maybe it helps someone in the future.

  1. Install Visual Studio Code with Python Extension and Git
  2. Install GTK/PyGObject, this needs to be compiled from the source:

2.1 Go to http://www.msys2.org/ and download the x86_64 installer. Follow the instructions on the page for setting up the basic environment. I recommend leaving the standard installation folder (C:\msys64), spaces in the install path may cause problems.

2.2 Install Visual Studio Community Edition with the C++ desktop development workload. 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. You can check with $env:path on the prompt if the path variable contains the gtk-build path. I also recommend leaving the standard installation folder, other paths may cause problems:

mkdir C:\gtk-build\github
cd C:\gtk-build\github
git clone https://github.com/wingtk/gvsbuild.git
cd C:\gtk-build\github\gvsbuild
python -m venv .venv
.\.venv\Scripts\activate.ps1
pip install .
pip install setuptools
$env:LIB = "C:\gtk-build\gtk\x64\release\lib;" + $env:LIB
$env:INCLUDE = "C:\gtk-build\gtk\x64\release\include;C:\gtk-build\gtk\x64\release\include\cairo;C:\gtk-build\gtk\x64\release\include\glib-2.0;C:\gtk-build\gtk\x64\release\include\gobject-introspection-1.0;C:\gtk-build\gtk\x64\release\lib\glib-2.0\include;" + $env:INCLUDE
gvsbuild build --enable-gi --py-wheel gtk4 pygobject

Note 'pip install setuptools' you need only on Python 3.12 or newer as the distutils pakacge is removed in Python 3.12 and the scripts still relies on it. Will hoepfully be fixed soon.

In Visual Studio Code

  1. Open a folder
  2. Command Palette -> Python: Create Environment
  3. Create venv environement
  4. Command Palette -> Python: Create Terminal
  5. Now on the Visual Studio Code command prompt with active Python environment enter:

pip install --force-reinstall (Resolve-Path C:\gtk-build\build\x64\release\pygobject\dist\PyGObject*.whl)

pip install --force-reinstall (Resolve-Path C:\gtk-build\build\x64\release\pycairo\dist\pycairo*.whl)

Of course this should also work without Visual Studio Code in an active Python environment.

Dialectology answered 26/11, 2023 at 19:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.