Installation of PyCairo on Windows

I see there is an old question about a similar thing here:

How do you install PyCairo (Cairo for Python) on Windows?

Since it's from 2012, I guess it's out of date.

I am trying to install pycairo on my Windows 7 64-bit laptop where I have Python 3.6.3 installed. I also have the latest setuptools installed if that matters.

I am facing the error below.

C:\Programs\Python36>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z


C:\Programs\Python36>pip install pycairo
Collecting pycairo
  Using cached pycairo-1.15.4.tar.gz
Installing collected packages: pycairo
  Running setup.py install for pycairo ... error
    Complete output from command c:\programs\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\petr
op01\\AppData\\Local\\Temp\\pip-build-vbfoifen\\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\petrop01\AppData\Local\Temp\
pip-rrp9zlme-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.6
    creating build\lib.win-amd64-3.6\cairo
    copying cairo\__init__.py -> build\lib.win-amd64-3.6\cairo
    running build_ext
    building 'cairo._cairo' extension
    creating build\temp.win-amd64-3.6
    creating build\temp.win-amd64-3.6\Release
    creating build\temp.win-amd64-3.6\Release\cairo
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\prog
rams\python36\include -Ic:\programs\python36\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:
\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-
IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tccairo/devic
e.c /Fobuild\temp.win-amd64-3.6\Release\cairo/device.obj
    device.c
    c:\users\petrop01\appdata\local\temp\pip-build-vbfoifen\pycairo\cairo\pycairo.h(37): fatal error C1083: Cannot open inclu
de file: 'cairo.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit statu
s 2

    ----------------------------------------
Command "c:\programs\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\petrop01\\AppData\\Local\\Te
mp\\pip-build-vbfoifen\\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\petrop01\AppData\Local\Temp\pip-rrp9zlme-record\inst
all-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\petrop01\AppData\Local\Tem
p\pip-build-vbfoifen\pycairo\

C:\Programs\Python36>

Since I am knew to Python and to all its things this sounds like too much for me. As far as I understand this pycairo is not a pure Python package so it requires a Visual C++ 14 compiler (which I just installed from here: http://landinghub.visualstudio.com/visual-cpp-build-tools, I took the 2015 version).

But I am still having the same issue when I run the pip install pycairo command.


You are trying to install pycairo from source on Windows, which requires a Windows C compiler.

You can try the Unofficial Windows Binaries for Python Extension Packages web site. You can find the last version of pycairo (1.15.4) for Python 3.6. It is distributed as a wheel package so you should install it with no pain.

This web site is a well known alternative for Windows developers.

To install, try:

pip install https://download.lfd.uci.edu/pythonlibs/gjr6o2id/pycairo-1.15.4-cp36-cp36m-win_amd64.whl

Or download the wheel, and install as follow:

pip install pycairo-1.15.4-cp36-cp36m-win_amd64.whl

If you really want to install from source, you can follow the guide on the Python Wiki. There is a stand alone Microsoft Visual C++ 14.0.


Pycairo now has Wheels. So simple

pip install pycairo

will work for Windows.