Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installation of PyCairo on Windows

Tags:

python

pycairo

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.

like image 619
peter.petrov Avatar asked Jan 06 '18 21:01

peter.petrov


People also ask

How do I install Pycairo?

Installing Pycairo requires pkg-config and cairo including its headers. Here are some examples on how to install those for some platforms: Ubuntu/Debian: sudo apt install libcairo2-dev pkg-config python3-dev

What version of Pycairo does Cairo work with?

It depends on cairo >= 1.15.10 and works with Python 3.6+. Pycairo, including this documentation, is licensed under the LGPL-2.1-only OR MPL-1.1. The Pycairo bindings are designed to match the cairo C API as closely as possible, and to deviate only in cases which are clearly better implemented in a more ‘Pythonic’ way.

What is Pycairo in Python?

Pycairo is a Python module providing bindings for the cairo graphics library. It depends on cairo >= 1.15.10 and works with Python 3.6+. Pycairo, including this documentation, is licensed under the LGPL-2.1-only OR MPL-1.1.

What license does Pycairo use?

Pycairo, including this documentation, is licensed under the LGPL-2.1-only OR MPL-1.1. The Pycairo bindings are designed to match the cairo C API as closely as possible, and to deviate only in cases which are clearly better implemented in a more ‘Pythonic’ way. Installing Pycairo requires cairo including its headers.


1 Answers

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.

like image 166
Laurent LAPORTE Avatar answered Oct 13 '22 11:10

Laurent LAPORTE