django OSError: no library called "cairo" was found on windows - python

When I run the Django server, I see this problem !!
OSError: no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so': error 0x7e
cannot load library 'libcairo.2.dylib': error 0x
cannot load library 'libcairo-2.dll': error 0x7e

Installing GTK+ didn't work for me.
I solved this problem using UniConverter2.0.
My environments is
Python 3.7
Windows 10 x64
Install uniconvertor-2.0rc4-win64_headless.msi,
Find the "dll" sub-directory under the UniConverter installation path.(In my case, C:\Program Files\UniConvertor-2.0rc4\dlls)
Add this "dll" path to the system path.
Close VSCode and reopen the project.
Try to run the server again.
Enjoy!

WeasyPrint needs the Pango, cairo and GDK-PixBuf libraries. They are part of GTK+ (formerly known as GIMP Toolkit), and must be installed separately.
After installing GTK+ libraries, do :
python -m weasyprint http://weasyprint.org weasyprint.pdf

Starting from Python 3.8, dll's need to be added separately.
Added GTK+, MSYS2, Visual Studio C Compiler and Uniconverter. But, nothing seemed to work.
Finally, got it working after putting the script for calling add_dll_directory.
import os
def set_dll_search_path():
# Python 3.8 no longer searches for DLLs in PATH, so we have to add
# everything in PATH manually. Note that unlike PATH add_dll_directory
# has no defined order, so if there are two cairo DLLs in PATH we
# might get a random one.
if os.name != "nt" or not hasattr(os, "add_dll_directory"):
return
for p in os.environ.get("PATH", "").split(os.pathsep):
try:
os.add_dll_directory(p)
except OSError:
pass
set_dll_search_path()
Source: PyCairo Windows Python3.8 Import Issue

See the solution here:
https://www.programmersought.com/article/47674569357/
You will need to add a path if not added after installations:
C:\Program Files\GTK3-Runtime Win64\bin
I have been solving it many times this way.

If you are using a lightweight Linux Docker Image, it may not include GTK as said above, then, you can include it by adding in your Dockerfile
RUN apt-get update -y
RUN apt-get install python3-cffi python3-brotli libpango-1.0-0 libharfbuzz0b libpangoft2-1.0-0 libgtk-3-dev gcc -y
Where all those packages are recommended to be installed by weasyprint and GCC has the GTK.

Ok I figure this out. you can have a 64 bit version of python that doesn't work. What I have found to work and this could change is the installing the 64 bit version of python from python's website, not from the Microsoft store!
remove any version of python you have installed
download https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.exe
install
download and install https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases
exact link is https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases/download/2021-04-29/gtk3-runtime-3.24.29-2021-04-29-ts-win64.exe
note that link is from https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#windows
add bin folder from that (sorry it was somebody else's machine, I use Ubuntu) in your environment path.
run through the first steps on weasyprint and you should be good to go!

Might be a bit late, but I just encoutered the same issue and:
Start here: https://weasyprint.readthedocs.io/en/stable/install.html#windows. Where you will find the links for the GTK Pack that contains the required DLLs.
In my case, I have a 64bit Python, so i use: "Download and run the latest gtk3-runtime-x.x.x-x-x-x-ts-win64.exe"
I did not change the installation directory
Once the installation is completed. I added the path to my variable paths.
I restarted the terminal, made sure I could locate the DLLs with : WHERE libcairo-2.dll. This retured C:\Program Files\GTK3-Runtime Win64\bin\libcairo-2.dll
Then I run python -m weasyprint http://weasyprint.org weasyprint.pdf
and got a few WARNINGs but they are just warnings :)

I have faced same error as well
I haved installed gtk as followed as gtk install in windows
Nothing worked
After that :
python -m pip install pycairo
solved the problem for me

Try this: https://cairocffi.readthedocs.io/en/stable/overview.html#installing-cairo-on-windows
And maybe this will work to: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pycairo
Best option is instal cairocffi trough pipwin
pip install pipwin
pipwin install cairocffi

Related

Failed to load a library: cairo

I keep getting this error when trying to run the following command:
python -m weasyprint http://weasyprint.org weasyprint.pdf
The error:
raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names))
OSError: dlopen() failed to load a library: cairo / cairo-2 / cairo-gobject-2 / cairo.so.2
I installed Weasyprint using pip install weasyprint. To install cairo i used this doc: https://weasyprint.readthedocs.io/en/latest/install.html
But, at the end of the guide, when i try to run WHERE libcairo-2.dll i get a not found error.
I have been following the guide step by step but it's not working and i keep getting the same error, i searched for various solutions but none of them fixes the issue. Any advice? Thanks in advance
You need to also install the GTK+ libraries (not just weasyprint), in order for weasyprint to render the final PDF.
You can find the installation instructions for your OS documented on weasyprint's website.
Dear Windows user, please follow these steps carefully.
Really carefully. Don’t cheat.
Besides a proper Python installation and a few Python packages,
WeasyPrint needs the Pango, cairo and GDK-PixBuf libraries. They are
required for the graphical stuff: Text and image rendering. These
libraries aren’t Python packages. They are part of GTK+ (formerly
known as GIMP Toolkit), and must be installed separately.
If you're running a 64bit version of windows you can grab the GTK installers from here.
Once you have that installed... Then running
python -m weasyprint http://weasyprint.org weasyprint.pdf
Should work as expected.
macOS Monterey, I resolved it by just brew install pango and it seems to install all the necessary dependencies including Cairo that I needed. My lucky day!

Is OpenCV 3.4.3 compatible with Python 3.6.7?

I am new to installing OpenCV and I want to install python 3.6.7 and a compatible OpenCV version. I want to install it on 64bit windows 10 laptop. How can I do this?
OK, if you are using python 3.6 - 64bits in windows OS (please be sure that it appear at the begin on your "python command line") first of all you have to go to this page: "https://www.lfd.uci.edu/~gohlke/pythonlibs/"
To install "opencv" library you first need "Numpy" library so let's download this right here:
let's download opencv library too:
There is an easy way to install these 2 libraries on windows:
1.- Unzip these files (I recommend you 7zip to do it) and in the case of numpy we will have this files:
Let's copy "Numpy" and "numpy-1.15.4+mkl.data" files (I have 1.14.0 version, don't worry about that) to this path: "Python36\Lib\site-packages" (the path to Python36 depends of where you installed it).
import numpy on your python command line, if not appear any error, we have finished of installing numpy on windows 10.
In the case of opencv is a little different,
when we unzip .whl file of opencv, we will have these files:
let's enter to "opencv_python-3.4.1.data" --> "data" --> "Lib" --> "site-packages". and then copy all files inside "site-packages" directory to "Python36\Lib\site-packages" (the same directory where we paste numpy library)
as same as in the case of numpy, import opencv on your python command line using "import cv2", if not appear any error, we have finished of installing opencv on windows 10.
There is another way to install .whl libraries on windows using PIP but you have to be sure that your python can be called from cmd (there is an option when you installed python called "add to path" to make this posible) also you have to have a good internet conection to prevent any posible error when installing. There are many tutorials in stackoverflow explaining PIP method. Hope this helps!.

Where did my python module install to?

I'm running python 3.6 via anaconda 3, using Visual Studio Code.
I followed instructions like these (Interactive Brokers API install) and downloaded the package to a local directory of mine say: c:\dev\pyib, so now the code is in c:\dev\pyib\IbPy-master
I open that directory in command line and run
python setup.py install
All runs ok.
But then my program, which is in c:\dev\pyib says Module not found. (In my case ibapi). The linter is also showing red.
There is no other python installed on this pc.
Where did the package install to? and how do I check that? What will I find where the package installed itself to that shows me its there?
Or do I have to use a trial-and-error with the linter and sys.path.append()? (I tried that with the directory where the files are downloaded to - to no avail)
I'm trying to set up the PYTHONPATH using the "env" in launch.json from Visual Studio Code, as shown in this unaccepted answer.
Current sys.path:
'c:\\dev\\pyIb',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\python36.zip',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\DLLs',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-
packages',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Babel-2.5.0-py3.6.egg',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Users\\user\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Pythonwin'
I deleted the ib directory and re-ran the install. The last line says: Writing C:\Users\user\AppData\Local\Continuum\anaconda3\Lib\site-pac‌​kages\IbPy2-0.8.0-py‌​3.6.egg-info So is the location of the egg-info the location of my undetected module? The actual folder in the site-packages is called ib.
Or could my problems be because of a difference in Lib vs. lib with the lowercase in the sys.path and the uppercase in the actual directory?
But the real question here is still: HOW DO I KNOW WHERE the package was installed what should I search for?
This answer is specific for anaconda3 Python and packages installed using python setup.py install (which is actually using distutils)
Take a look at anaconda3\Lib\site-packages you should see a directory for the package you installed.
The way to know for sure where your package is, is by doing a pip list then trying to pip uninstall and re-install again using the python setup.py install: Here are the detailed instructions:
When uninstalling, pip will tell you it cannot because it was done via distutils.
You'll get a message like this:
DEPRECATION: Uninstalling a distutils installed project (ibpy2) has been deprecated and will be removed in a future version.
This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
You'll be prompted to continue anyway. If you choose No, then you can find the directory in
C:\Users\<yourusername>\AppData\Local\Continuum\anaconda3\Lib\site-packages
Thanks to Emanuel Mtali for pointing me in the right direction
Some more information:
The problem I had was due to a stupid mistake of mine. I was running setup of a different (but related) package not used anymore. IbPy2 instead of TwsAPI. I was supposed to run the setup.py of the package installed via the latest version of the MSI from IB, and NOT the IbPy2 package. :-(

I cannot install dipy library for python, why ? In the description I explain what I did

I went to http://nipy.org/dipy/installation.html and install nibabel, then I when I wanted to install dipy, there where 2 problems:
Wheel was not built
and vcvarshall.bat not found.
What I did ?
Install Setuptools in site-pakcages
download Setuptools-34.3.1-py2.py3-none-any.whl (md5) and save in site-packages
I also try
python setup.py install --compiler=mingw32ç
and
If you get an error saying unable to find vcvarsall.bat then you need to create a file called pydistutils.cfg in notepad and give it the contents
[build]
compiler=mingw32
But setup.py de system it did not find, and I still have vcvarshall.bat not found.
what I need to do?
I am using, Windows 7, Python 3.5.1 and Anaconda 2.5.0 (64 bit)
You will almost certainly find it easier to install third-party packages if you adopt virtual environments. When done correctly you will then not need admin privileges to install packages into virtualenvs. The HitchHikers' Guide to Python contains more information about this.
The vcvarsall.bat is, I believe, a part of the Visual Studio (the Express version is available at no cost) environment. It's required when you are trying to build a compiled Python extension as described in this article. I'm not sure how that will play with mingw.
So, I installed via ANACONDA but , when I go to python, and I want to import dipy it says: No modle named dipy
Solved ! Well I had python 3.5 and dipy has some issues with that version, so I installed Anaconda with python 2.7 , installed visual c++9 and follow the steps on the web !

PyOpenGL glutInit NullFunctionError

I am running Anaconda Python 2.7 on a Win7 x64 machine and used
pip install PyOpenGL PyOpenGL_accelerate
at the Anaconda command line to install PyOpenGL.
I have some code (not my own I must confess) that makes use of glutInit
import sys
import math
import numpy
import OpenGL
from OpenGL.GL import *
from OpenGL.GLUT import *
import Image
import linkage
# ... a whole load of definitions etc ...
glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glutInitWindowSize(600, 600)
glutCreateWindow('linkage')
init()
initWindow()
glutIdleFunc(idle)
glutMainLoop()
I run by entering the following at the command line:
python main.py peaucellier.txt
But then get the following error (line 371 is the glutInt(sys.argv) line above)
File "C:/Users/Owner/Documents/Python Scripts/linkage/main.py", line 371, in <module>
glutInit(sys.argv)
File "C:\Anaconda\lib\site-packages\OpenGL\GLUT\special.py", line 333, in glutInit
_base_glutInit( ctypes.byref(count), holder )
File "C:\Anaconda\lib\site-packages\OpenGL\platform\baseplatform.py", line 407, in __call__
self.__name__, self.__name__,
NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling
I have looked at similar errors posted in this forum but none of the proposed fixes are working which is why I'm asking, what's wrong here?
Is the installation at fault? Are the imports correct?
EDIT: After trying many many fixes for the official release I am now using an unofficial release that works perfectly from Unofficial Windows Binaries for Python Extension Packages
According to the link below the problem was with the glut installation rather than pip install. It seems glut files are not part of PyOpenGL or PyOpenGL_accelerate package. You have to download them seperately.
https://stackoverflow.com/a/39181193/7030177
Windows user can use the link below to download glut as mentioned in the given link.
ftp://ftp.sgi.com/opengl/glut/glut3.html.old#windows
Linux Users can just install glut using the following command:
sudo apt-get install freeglut3-dev
Hope this helps :)
After looking around for a solution to a similar problem I ran across this google group that answers the question: https://groups.google.com/forum/#!topic/glumpy-users/aC1NjEHXtEE
There is a problem with OpenGL.GLUT when downloaded as pip from the official source. Uninstall OpenGL using pip, then download OpenGL from http://www.lfd.uci.edu/~gohlke/pythonlibs/
For people on Linux with this error after installing via easy_install PyOpenGL or pip install PyOpenGL.
-> Install the distribution package as: sudo apt-get install python-opengl - this works for me.
If installing PyOpenGL from easy_install, pip or conda, make sure that you have already installed a GLUT implementation, such as FreeGLUT (prebuilt Windows binaries).
For FreeGLUT, copy the distributed files to a location on your hard drive and then add the path to the bin directory (which contains the GLUT DLLs) to your PATH environment variable. Then PyOpenGL should work as expected.
It is mainly because you're running 64-bit windows put pip is installing 32-bit version of PyOpenGL.
To fix this, follow these steps:
Uninstall existing PyOpenGL, Run pip uninstall PyOpenGL PyOpenGL_accelerate
Download the 64-bit builds of PyOpenGL and PyOpenGL accelerate from here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl
How to choose which one to download? Well, first you need to check your python version. Run python --version to determine.
Then according to your version download the whl files for PyOpenGL and PyOpenGL accelerate. For example, if you have Python 3.8, download these 2 files:
PyOpenGL‑3.1.5‑cp38‑cp38‑win_amd64.whl
PyOpenGL_accelerate‑3.1.5‑cp38‑cp38‑win_amd64.whl
Similarly, if you run Python 3.9, download these instead:
PyOpenGL‑3.1.5‑cp39‑cp39‑win_amd64.whl
PyOpenGL_accelerate‑3.1.5‑cp39‑cp39‑win_amd64.whl
Note: Must download amd64 ones, after all, you're running 64-bit windows.
Now go to the folder where you downloaded the files and run powershell/cmd with administrator there.
Use pip to force install those files. For example:
pip install PyOpenGL-3.1.5-cp38-cp38-win_amd64.whl --force-reinstall
pip install PyOpenGL_accelerate-3.1.5-cp38-cp38-win_amd64.whl --force-reinstall
Note: Install PyOpenGL first and then PyOpenGL_accelerate
If the installation succeeds, you may be able now to run.
Some facts to make sure:
*All platforms must be of the same bit version.
*System type, python, OpenGL needs to be of the same bit version. In my case it was x64 bit
*It is necessary to restart your desktop if you reinstall any one of them (Python, OpenGL)
*It is recommended to keep your pip version at 20.3, I downgraded it from 21.1.3
I got the same error and a solved installing required files from here.
Download these files:
PyOpenGL-3.1.1-cp27-cp27m-win32.whl (download if your computer 32 bits )
PyOpenGL-3.1.1-cp27-cp27m-win_amd64.whl (download if your computer 64 bits )
PyOpenGL_accelerate-3.1.1-cp27-cp27m-win32.whl (download if your computer 32 bits )
PyOpenGL_accelerate-3.1.1-cp27-cp27m-win_amd64.whl (download if your computer 64 bits )
install these .whl files for 64 bits:
pip install PyOpenGL-3.1.1-cp27-cp27m-win_amd64.whl
pip install PyOpenGL_accelerate-3.1.1-cp27-cp27m-win_amd64.whl
install these .whl files for 32 bits:
pip install PyOpenGL-3.1.1-cp27-cp27m-win32.whl
pip install PyOpenGL_accelerate-3.1.1-cp27-cp27m-win32.whl
for python 2.7, PyopenGL needs vc++ 9 compiler, download and install it.
then:
python -m pip install --upgrade pip
pip install image
pip install numpy
pip install PyOpenGL PyOpenGL_accelerate
I downloaded freeglut
unzipped it and added bin directory to the path
when calling: glutCreateWindow("sometitle")
changed to glutCreateWindow(b'sometitle')
and got it run on windows 7
My case is different, Python 3.6 and windows 10. However exactly same error message. Tried all above solutions, no success.
Downloaded WHL file right to my computer and version of python from HERE
Then pip installs filename.Whl, no more issue!
The answer was from a Chinese website: Answer Link
Yes, this happened to me on Windows 10 running python 2.713 anaconda 4 64 bit. I had used conda to install pyopengl but received the same error as above. So I downloaded freeglut from transmissionzero and just copied the freeglut.dll (64 bit for me) to the same directory as my source file (it just needs to be in the dll searchpath) and all was good.
I know it is a little late. I also encountered this problem with python 2.7 (32 bits) in windows. I tried the method mentioned by user2723240 but still failed. Finally, I solved this problem by copying glue32.dll to System32 in C drive and copy glue32.dll into my source file directory. It works well now.
On linux, the pyopengl module attempts to use ctypes module to load the glut library as simply 'glut'. According to ctypes documentation the loadLibrary routine must be given the complete filename. Therefore, I made a symbolic link to libglut.so and named it 'glut' and everything just worked.
The following command should work for Anaconda users:
conda install -c conda-forge freeglut
https://anaconda.org/conda-forge/freeglut
On windows, although PyOpenGL says it installs freeglut by default, it does not.
To patch it, you must download or compile freeglut (other answers here contain the appropriate links) and place it in a new site-packages/OpenGL/DLLS folder inside to your existing OpenGL site-packages installation.
Once there, the freeglut.dll needs to have the bits and the MSVC version appended to the filename. OpenGL/platform/win32.py has the details on exactly how it's detected.
To make it clearer the filename needs to be the one printed from the following script:
import sys
import platform
if sys.hexversion < 0x2070000:
vc = 'vc7'
elif sys.hexversion >= 0x3050000:
vc = 'vc14'
elif sys.hexversion >= 0x3030000:
vc = 'vc10'
else:
vc = 'vc9'
size = platform.architecture()[0].strip('bits')
print(f'freeglut{size}.{vc}.dll')
Step 1
Install python in your system windows 10/11 preferred. for python 3.8.0 : https://www.python.org/ftp/python/3.8.0/python-3.8.0-amd64.exe
If you have already installed then check for your python version
Open terminal and type "python --version"
it will display your python version. for example I have installed python 3.8.0.
Step 2
Next open terminal and run the below command
python -m pip install --upgrade pip==20.3
sometimes you have higher version of pip installed but its okay to downgrade back to version 20.3
Step 3
now for installing OpenGL go to this site : https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl
and download
PyOpenGL‑3.1.6‑cp38‑cp38‑win_amd64.whl (for 64bit windows) or
PyOpenGL‑3.1.6‑cp38‑cp38‑win32.whl (for 32 bit)
and
PyOpenGL_accelerate‑3.1.6‑cp38‑cp38‑win_amd64.whl (for windows 64bit) or
PyOpenGL_accelerate‑3.1.6‑cp38‑cp38‑win32.whl (for windows 32bit)
Note : I have in installed python 3.8.0. so I downloaded PyOpenGL having cp38 word in it. If you have installed python 3.9 or other version download the above mentioned file having name cp39,cp10 etc.
after downloading both files according to your python version. put it a folder.
Step 4
then open terminal from that folder. Windows 10 lets you launch Command Prompt in a folder through the File Explorer's address bar. Type “cmd” in the address bar and then hit Enter
after opening terminal enter the below command
pip install PyOpenGL-3.1.6-cp38-cp38-win_amd64.whl --force-reinstall
then after installing it run the below command
pip install PyOpenGL_accelerate-3.1.6-cp38-cp38-win_amd64.whl --force-reinstall
Note : Don't forget to change the file name ( e.g. : PyOpenGL-3.1.6-cp38-cp38-win_amd64.whl) to the file name that you have downloaded.

Categories