- Get link
- X
- Other Apps
Posted by
Naveen M K
on
- Get link
- X
- Other Apps
So, you have been here just to install a Python Library in Windows. Let me give an introduction about it.
What is Pycairo?
Pycairo is a Python module providing bindings for the Cairo graphics library. It depends on Cairo >= 1.13.1 and works
with Python 3.5+. Also, Cairo is a 2D graphics library with support for multiple output
devices. Currently, supported output targets include the
X Window System (via both Xlib and XCB), Quartz, Win32, image buffers,
PostScript, PDF, and SVG file output. So, you can create beautiful Images using Programs in Python after installing Pycairo. You could have tried something like
But it usually fails if your PC is not configured for it. You may find the below guide helpful if you want to install it.pip install pycairo
Installing Pycairo
Installing Unofficial Binaries - Easiest One
Installing using this method is considered unofficial as Pycairo as of 4 July 2020, not yet provides Wheels (Binaries) which would make the install easy, can be directly installed
pip
. Now, in this method, we are downloading those binaries from another site and installing it in your PC. So you can follow the steps below for it.➜ Using the Script from Manim Community
This method uses the script which was created and maintained by the folks of Manim Community. Sometimes the URL may fail because those binaries are not hosted in the same place. So if you are lucky enough it may work for you and you would just complete it vary easily.
- Open Powershell or any other Elevated Command Shell which is Supported for Web Requests.
- Copy and Paste the below command in it.
- That you would automatically install PyCairo if it succeeds with no Error. If this fails Follow other methods below. Also, if that method fails you can open an issue here.
(Invoke-WebRequest -Uri https://raw.githubusercontent.com/ManimCommunity/manim/master/scripts/pycairoinstall.py -UseBasicParsing).Content | py -3
➜ Directly downloading Binaries
- Go and visit the Download Page.
- Select the download that corresponds to your PC's architecture and Python Version.
cp38
corresponds to Python 3.8,cp37
corresponds to Python 3.7, etcwin_amd64
corresponds to 64-bit machines,win32
corresponds to 32-bit machines. You could see https://www.python.org/dev/peps/pep-0427/#id11 for more reference.- Open your Command Prompt and enter the directory where you downloaded the file by typing
cd C:\path\to\cairo
- Finally, run
pip install (cairo-file).whl
, where the file the appropriate name of the.whl
file. For example, see below.
pip install pycairo-1.19.1-cp38-cp38-win_amd64.whl
If you have multiple Python version installed use below to select the version.py -3.8 -m pip install pycairo-1.19.1-cp38-cp38-win_amd64.whl
- Here, I selected Python 3.8 above. If
import pycairo
works then you are good to go. This would complete the installation of PyCairo.
Installing Official Binaries - Requires C compiler
If you are the person, who wants actually need to compile from the source or from the using pip. You should first get suitable C compilers. Refer Python Wiki for your required C compiler. You should get your Cairo binaries from https://github.com/preshing/cairo-windows/releases or build the one you need refer https://www.cairographics.org/end_to_end_build_for_win32/ if you want to build it.
After that set the environment variable
INCLUDE
to point to the path of binaries INCLUDE FOLDER. And also another environment variable called LIB and the value is to the path where cairo.dll
and cairo.lib
is located. You could see below for setting it.setx INCLUDE C:\path\to\header\files
setx LIB C:\path\\to\dll\files
After that, the below default pip install would work.pip install pycairo
Great you have successfully installed PyCairo and import pycairo
works.
Comments
Post a Comment