Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeWarning: Failed to import CairoSVG #69

Closed
AndrewHartAR opened this issue Jan 1, 2022 · 7 comments
Closed

RuntimeWarning: Failed to import CairoSVG #69

AndrewHartAR opened this issue Jan 1, 2022 · 7 comments

Comments

@AndrewHartAR
Copy link

I've followed the instructions and installed Cairo with brew install cairo. I've also tried other ways, through pip install etc. to try and get rid of this error, but can't. This is the error I get when simply running a file with import drawSvg:

RuntimeWarning: Failed to import CairoSVG. drawSvg will be unable to output PNG or other raster image formats. See https://github.com/cduck/drawSvg#prerequisites for more details.
Original OSError: no library called "cairo-2" was found
no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so.2': dlopen(libcairo.so.2, 0x0002): tried: 'libcairo.so.2' (no such file), '/usr/local/lib/libcairo.so.2' (no such file), '/usr/lib/libcairo.so.2' (no such file), '/Users/andrew/Code/ai/ai4/libcairo.so.2' (no such file), '/usr/local/lib/libcairo.so.2' (no such file), '/usr/lib/libcairo.so.2' (no such file)
cannot load library 'libcairo.2.dylib': dlopen(libcairo.2.dylib, 0x0002): tried: 'libcairo.2.dylib' (no such file), '/usr/local/lib/libcairo.2.dylib' (no such file), '/usr/lib/libcairo.2.dylib' (no such file), '/Users/andrew/Code/ai/ai4/libcairo.2.dylib' (no such file), '/usr/local/lib/libcairo.2.dylib' (no such file), '/usr/lib/libcairo.2.dylib' (no such file)
cannot load library 'libcairo-2.dll': dlopen(libcairo-2.dll, 0x0002): tried: 'libcairo-2.dll' (no such file), '/usr/local/lib/libcairo-2.dll' (no such file), '/usr/lib/libcairo-2.dll' (no such file), '/Users/andrew/Code/ai/ai4/libcairo-2.dll' (no such file), '/usr/local/lib/libcairo-2.dll' (no such file), '/usr/lib/libcairo-2.dll' (no such file)
  warnings.warn(msg, RuntimeWarning)
@cduck
Copy link
Owner

cduck commented Jan 2, 2022

Thanks for the report. Can you give a few more details to help determine the issue?

  • macOS version (Apple menu > About This Mac)
  • brew cairo version (brew info cairo)
  • All pip packages (python3 -m pip freeze) Use the same python command that you use to run your scripts, followed by -m pip freeze.
  • Python version (python3 --version)

In case this is an interaction with another package, could you also create a fresh Python virtual environment, install only drawSvg, then try import drawSvg?

@AndrewHartAR
Copy link
Author

macOS 12.0.1 (M1X MacBook Pro if that's helpful.. I know this worked on an older Intel MBP, albeit with different environmental factors)
cairo 1.16.0

cairocffi==1.3.0
CairoSVG==2.5.2
cffi==1.15.0
cssselect2==0.4.1
cycler==0.11.0
defusedxml==0.7.1
drawSvg==1.8.3
imageio==2.13.5
kiwisolver==1.3.2
matplotlib==3.4.3
numpy==1.21.3
pandas==1.3.4
Pillow==8.4.0
plotly==5.3.1
pycparser==2.21
pyparsing==3.0.4
python-dateutil==2.8.2
pytz==2021.3
six==1.16.0
tenacity==8.0.1
tinycss2==1.1.1
webencodings==0.5.1

Python 3.10.0

Same error on a new environment with a file which simple has import drawSvg

RuntimeWarning: Failed to import CairoSVG. drawSvg will be unable to output PNG or other raster image formats. See https://github.com/cduck/drawSvg#prerequisites for more details.
Original OSError: no library called "cairo-2" was found
no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so.2': dlopen(libcairo.so.2, 0x0002): tried: 'libcairo.so.2' (no such file), '/usr/local/lib/libcairo.so.2' (no such file), '/usr/lib/libcairo.so.2' (no such file), '/Users/andrew/Code/ai/ai4/libcairo.so.2' (no such file), '/usr/local/lib/libcairo.so.2' (no such file), '/usr/lib/libcairo.so.2' (no such file)
cannot load library 'libcairo.2.dylib': dlopen(libcairo.2.dylib, 0x0002): tried: 'libcairo.2.dylib' (no such file), '/usr/local/lib/libcairo.2.dylib' (no such file), '/usr/lib/libcairo.2.dylib' (no such file), '/Users/andrew/Code/ai/ai4/libcairo.2.dylib' (no such file), '/usr/local/lib/libcairo.2.dylib' (no such file), '/usr/lib/libcairo.2.dylib' (no such file)
cannot load library 'libcairo-2.dll': dlopen(libcairo-2.dll, 0x0002): tried: 'libcairo-2.dll' (no such file), '/usr/local/lib/libcairo-2.dll' (no such file), '/usr/lib/libcairo-2.dll' (no such file), '/Users/andrew/Code/ai/ai4/libcairo-2.dll' (no such file), '/usr/local/lib/libcairo-2.dll' (no such file), '/usr/lib/libcairo-2.dll' (no such file)
  warnings.warn(msg, RuntimeWarning)

Hope this is helpful.

@cduck
Copy link
Owner

cduck commented Jan 2, 2022

Also what brew cairo version? Below is mine. I cannot reproduce with your venv, Python 3.10.0 (installed from brew: /usr/local/opt/[email protected]/bin/python3.10), macOS 12.1, and cairo 1.16.0.

Can you try a version of Python installed through brew? Other versions of cairo?

% brew info cairo
cairo: stable 1.16.0 (bottled), HEAD
Vector graphics library with cross-device output support
https://cairographics.org/
/usr/local/Cellar/cairo/1.16.0_5 (126 files, 6.3MB) *
  Poured from bottle on 2021-04-08 at 21:49:57
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/cairo.rb
License: LGPL-2.1-only or MPL-1.1
==> Dependencies
Build: pkg-config ✔
Required: fontconfig ✔, freetype ✔, glib ✔, libpng ✔, libx11 ✔, libxcb ✔, libxext ✔, libxrender ✔, lzo ✔, pixman ✔
==> Options
--HEAD
	Install HEAD version

@AndrewHartAR
Copy link
Author

cairo: stable 1.16.0 (bottled), HEAD
Vector graphics library with cross-device output support
https://cairographics.org/
/opt/homebrew/Cellar/cairo/1.16.0_5 (126 files, 6.4MB) *
  Poured from bottle on 2022-01-01 at 13:04:15
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/cairo.rb
License: LGPL-2.1-only or MPL-1.1
==> Dependencies
Build: pkg-config ✔
Required: fontconfig ✔, freetype ✔, glib ✔, libpng ✔, libx11 ✔, libxcb ✔, libxext ✔, libxrender ✔, lzo ✔, pixman ✔
==> Options

I wonder if it's something to do with being an M1 Mac. I believe I followed this guide to setup virtualenv using conda, or something like that, because otherwise I was running into many errors. But still, checking the cairo version using conda gives the same result.

@cduck
Copy link
Owner

cduck commented Jan 3, 2022

OK. Sounds like dynamic library compatibility on the M1 may be the problem. If import cairosvg also gives the error, you should report this to the Cairo SVG project and/or Cairo.

@AndrewHartAR
Copy link
Author

AndrewHartAR commented Jan 3, 2022 via email

@cduck cduck closed this as completed Jan 14, 2022
@sblOWPCKCR
Copy link

Posted a workaround here: Kozea/CairoSVG#354 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants