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!
Related
I installed opencv-python on ubuntu wsl, after setting up a venv using virtualenvwrapper (I use wsl in visual studio code).
When running this code (which appears in one of the articles of this OCR guide:
import argparse
import cv2
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True)
args = vars(ap.parse_args())
image = cv2.imread(args["image"])
cv2.imshow("I", image)
with this command on teminal:
python script.py --image temp.png
I get:
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/ben123/.local/bin/.virtualenvs/ocr_venv/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb.
The interpreter in vscode is the correct one (the one of the venv), and when I type pip list I get
Package Version
------------- --------
numpy 1.22.2
opencv-python 4.5.5.62
pip 22.0.3
setuptools 60.6.0
wheel 0.37.1
Would appreciate any help at this point, since I spent so much time and didn't get nowhere.
Things I tried:
following this guide to install it. Gave the same error.
following an older guide from this site, was much more complicated and didn't work as well.
uninstalling opencv-python and installing opencv-python again/ opencv-python-contrib/ opencv-python-headless/ opencv-python-contrib-headless (only one of them at a time)
following this thread because it has similar problem
literally reset my wsl several times just to make sure I don't have multiple pythons/ opencv versions that mess this up.
tried installing (to a wsl venv) opencv directly with the official documentation
Tried to give up on wsl completely and install opencv using anaconda but even that didn't work.
Just delete cv2.imshow from your code. Your OS is without graphics and can't display image
I had the same error in a completely different context.
Found that the problem was a PyQt5 installation in my virtual environment.
Check if you have a PyQt in the path
/home/ben123/.local/bin/.virtualenvs/ocr_venv/lib/python3.8/site-packages/
if so, remove it
$ pip uninstall <PyQT package installed>
example:
$ pip uninstall PyQt5
Then reinstall opencv-python
$ pip uninstall opencv-python
$ pip install opencv-python
Hope that works!
To display graphical information about wsl, you should configure x11 related content.
eg: You can use MobaXterm for graphical display.
Uninstalling opencv and installing similar headless version worked for me.
$ pip install opencv-python-headless
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
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 !
During the installation phase, I get this, "Unable to find vcvarsall.bat" error. The installation process did complete, though. However, I was unable to see the shell on my desktop (I am using windows) and neither was I able to open it manually. I scoured the internet for the error but was unable to find any solution for this case.
The installation process is through a superpack that downloads Python 2.7
SimpleCV is not receiving much love in the past few years, and most of it's code don't got upgrade like the libraries it depends on.
The problem you got is the Superpack trying to compile an older version of OpenCV.
When running the Superpack, you should have seen and redtext error, and if you try to run a code it should show you something like this:
File "C:\Python27\lib\site-packages\SimpleCV\base.py", line 59, in <module>
raise ImportError("Cannot load OpenCV library which is required by SimpleCV")
ImportError: Cannot load OpenCV library which is required by SimpleCV
There are a few paths you can try from there:
1. You can try to install Microsoft Visual C++ Compiler for Python 2.7
Uninstall everything SuperPack installed in your PC or it may not work
It may fixes some other uses when using pip.
Now you have to install SimpleCV again.
2. Try to install OpenCV(2.3) on your own:
You can use pip for it, just remember to chose 32bits to keep compatibility with (Super Pack)
Just run on CMD
pip install OpenCV or python -m pip install OpenCV
3. Give up on SuperPack and install everything on your own.
You can try this guide
https://github.com/sightmachine/SimpleCV#windows-7vista
Or use pip for all dependencies
numpy (Numpy+MKL make sure to install this one first)
scipy
PIL
ipython
svgwrite
pygame==1.9.1release
OpenCV
You can find a useful list of wheels here
http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
Sources:
https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/
http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
https://github.com/sightmachine/SimpleCV#windows-7vista
I installed libtorrent-rasterbar on a mac with brew. After I installed I check if it was good installed with the command:
brew install libtorrent-rasterbar
And I get:
Warning: libtorrent-rasterbar-0.16.10 already installed
So installation looks to be ok.
If I go to python and type "import libtorrent" y get an error.
Also if I type:
>>>help('modules')
I dont see libtorrent in the list.
What I'm doing wrong?
Brew has nothing to do with Python. It'll just install system libraries. If you want to install libraries/modules for Python, you should use pip (recommended) or easy_install.
I couldn't find very good Python support for libtorrent in particular, although there is great support for other torrent libraries like PyTorrent.
If you must use libtorrent-rasterbar, there's a great tutorial on how to do it on Super User