7

I have been trying to install pycairo for three days and I was wondering whether anyone could reproduce the error or if I am slowly starting to turn mad.

What I have tried:

I looked at the answers from Installation of PyCairo on Windows and How do you install PyCairo (Cairo for Python) on Windows?.

I tried installing pycairo using a file downloaded from Python Extension Packages for Windows but it says ERROR: pycairo-1.19.1-cp38-cp38-win32.whl is not a supported wheel on this platform. I used the following command pip install "C:\Users\...\Downloads\pycairo-1.19.1-cp38-cp38-win32.whl"

I tried installing pycairo via pip pip install pycairo which gives me a really long error message:

Collecting pycairo
  Using cached pycairo-1.19.1.tar.gz (205 kB)
Installing collected packages: pycairo
    Running setup.py install for pycairo ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\caspa\appdata\local\programs\python\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\caspa\\AppData\\Local\\Temp\\pip-install-tjiuwot4\\pycairo\\setup.py'"'"'; __file__='"'"'C:\\Users\\caspa\\AppData\\Local\\Temp\\pip-install-tjiuwot4\\pycairo\\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\caspa\AppData\Local\Temp\pip-record-pbvjvlu1\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\caspa\appdata\local\programs\python\python37-32\Include\pycairo'
         cwd: C:\Users\caspa\AppData\Local\Temp\pip-install-tjiuwot4\pycairo\
    Complete output (18 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.7
    creating build\lib.win32-3.7\cairo
    copying cairo\__init__.py -> build\lib.win32-3.7\cairo
    copying cairo\__init__.pyi -> build\lib.win32-3.7\cairo
    copying cairo\py.typed -> build\lib.win32-3.7\cairo
    running build_ext
    building 'cairo._cairo' extension
    creating build\temp.win32-3.7
    creating build\temp.win32-3.7\Release
    creating build\temp.win32-3.7\Release\cairo
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -DPYCAIRO_VERSION_MAJOR=1 -DPYCAIRO_VERSION_MINOR=19 -DPYCAIRO_VERSION_MICRO=1 -Ic:\users\caspa\appdata\local\programs\python\python37-32\include -Ic:\users\caspa\appdata\local\programs\python\python37-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.7.2\include\um" "-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" /Tccairo/device.c /Fobuild\temp.win32-3.7\Release\cairo/device.obj
    device.c
    C:\Users\caspa\AppData\Local\Temp\pip-install-tjiuwot4\pycairo\cairo\pycairo.h(37): fatal error C1083: Datei (Include) kann nicht ge”ffnet werden: "cairo.h": No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.24.28314\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\caspa\appdata\local\programs\python\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\caspa\\AppData\\Local\\Temp\\pip-install-tjiuwot4\\pycairo\\setup.py'"'"'; __file__='"'"'C:\\Users\\caspa\\AppData\\Local\\Temp\\pip-install-tjiuwot4\\pycairo\\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\caspa\AppData\Local\Temp\pip-record-pbvjvlu1\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\caspa\appdata\local\programs\python\python37-32\Include\pycairo' Check the logs for full command output.

I get the same error message when trying to install PyGoject, which contains pycairo, via pip.

I found something that should be supposed to fix the error, but unfortunately the link in the forum is dead. I went to the official download page (I believe) cairographics.org and its a dead link as well.

Another thing I tried: I went to the Cairo Docs on getting started, but it's unfortunately only for Ubuntu/Linux/IOS.

4
  • When you try to install using pip do you run cmd as administrator?
    – Thomas
    Commented Mar 20, 2020 at 17:57
  • 3
    "pycairo-1.19.1-cp38-cp38-win32.whl is not a supported wheel on this platform" The wheel is for 32-bit Python 3.8. Either your Python is not 3.8 or it's not 32-bit. If you gonna use Python 3.8 64-bit download a wheel for 64-bit Python 3.8.
    – phd
    Commented Mar 20, 2020 at 18:09
  • I'm using python 3.7.4 32 Bit, I did try running it as an administrator, same error unfortunatly. But thanks for your comments. Commented Mar 20, 2020 at 20:14
  • Then download and install from pycairo-1.19.1-cp37-cp37m-win32.whl?
    – hoefling
    Commented Mar 20, 2020 at 22:33

2 Answers 2

10

I've ran into a similar error to this as well, so here's what worked for me. Go to https://pycairo.readthedocs.io/en/latest/getting_started.html for more info. You'll have to run one of these five commands to set up pkg-config on your computer prior to running the install command.

  • Ubuntu/Debian: sudo apt install libcairo2-dev pkg-config python3-dev
  • macOS/Homebrew: brew install cairo pkg-config
  • Arch Linux: sudo pacman -S cairo pkgconf
  • Fedora: sudo dnf install cairo-devel pkg-config python3-devel
  • penSUSE: sudo zypper install cairo-devel pkg-config python3-devel

Then run: import cairo

Hope that works!

0

I'm new with Python, so I'm not really sure what's going on, but this works for me.

Simply change the "pip" to "pip3" and it'll magically work. As of this writing, I'm using Python 3.8 64-bit so my command is this:

pip3 install pycairo-1.19.1-cp38-cp38-win_amd64.whl

From what I understand, this seems to be an incompatibility since Python 2 life has ended and lost support just early this year. So pretty much all the tutorial is outdated and didn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.