已安装cairosvg和cairocffi但导入时出错

时间:2017-06-21 21:00:37

标签: python python-3.x cairo

当我尝试安装cairosvg时,表示要求已满足。

Requirement already satisfied: cairosvg in 
c:\users\kshitij\appdata\local\programs\python\python35\lib\site-packages
Requirement already satisfied: cairocffi in 
c:\users\kshitij\appdata\local\programs\python\python35\lib\site-packages 
(from cairosvg)
Requirement already satisfied: lxml in 
c:\users\kshitij\appdata\local\programs\python\python35\lib\site-packages 
(from cairosvg)
Requirement already satisfied: cssselect in 
c:\users\kshitij\appdata\local\programs\python\python35\lib\site-packages 
(from cairosvg)
Requirement already satisfied: pillow in 
c:\users\kshitij\appdata\local\programs\python\python35\lib\site-packages 
(from cairosvg)
Requirement already satisfied: tinycss in 
c:\users\kshitij\appdata\local\programs\python\python35\lib\site-packages 
(from cairosvg)
Requirement already satisfied: cffi>=0.6 in 
c:\users\kshitij\appdata\local\programs\python\python35\lib\site-packages 
(from cairocffi->cairosvg)
Requirement already satisfied: olefile in 
c:\users\kshitij\appdata\local\programs\python\python35\lib\site-packages 
(from pillow->cairosvg)
Requirement already satisfied: pycparser in 
c:\users\kshitij\appdata\local\programs\python\python35\lib\site-packages 
(from cffi>=0.6->cairocffi->cairosvg)

但是当我尝试在IDLE中导入它时,它会出现以下错误:

import cairosvg
File "C:\Users\Kshitij\AppData\Local\Programs\Python\Python35\lib\site-
packages\cairosvg\__init__.py", line 29, in <module>
 from . import surface
File "C:\Users\Kshitij\AppData\Local\Programs\Python\Python35\lib\site-
packages\cairosvg\surface.py", line 24, in <module>
import cairocffi as cairo
File "C:\Users\Kshitij\AppData\Local\Programs\Python\Python35\lib\site-
packages\cairocffi\__init__.py", line 41, in <module>
cairo = dlopen(ffi, *CAIRO_NAMES)
File "C:\Users\Kshitij\AppData\Local\Programs\Python\Python35\lib\site-
packages\cairocffi\__init__.py", line 34, in dlopen
return ffi.dlopen(names[0])  # pragma: no cover
File "C:\Users\Kshitij\AppData\Local\Programs\Python\Python35\lib\site-
packages\cffi\api.py", line 140, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:\Users\Kshitij\AppData\Local\Programs\Python\Python35\lib\site-
packages\cffi\api.py", line 786, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "C:\Users\Kshitij\AppData\Local\Programs\Python\Python35\lib\site-
packages\cffi\api.py", line 781, in _load_backend_lib
raise OSError(msg)
OSError: cannot load library libcairo.so.2: error 0x7e.  Additionally, 
ctypes.util.find_library() did not manage to locate a library called 
'libcairo.so.2'

这可能是因为cairocffi,因为它在导入时也会出现以下错误:

import cairocffi
File "C:\Users\Kshitij\AppData\Local\Programs\Python\Python35\lib\site-
packages\cairocffi\__init__.py", line 41, in <module>
cairo = dlopen(ffi, 'cairo', 'cairo-2')
File "C:\Users\Kshitij\AppData\Local\Programs\Python\Python35\lib\site-
packages\cairocffi\__init__.py", line 38, in dlopen
raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names))
OSError: dlopen() failed to load a library: cairo / cairo-2

我有一个64位基于Windows的架构与python 3.5并安装了cairocffi-0.8.0安装没有问题。

1 个答案:

答案 0 :(得分:0)

我使用UniConverter2.0解决了这个问题。 我的环境是

  • Python 3.7
  • Windows 10 x64
  1. 安装uniconvertor-2.0rc4-win64_headless.msi
  2. 在UniConverter安装路径下找到“ dll”子目录。(在我的情况下为C:\Program Files\UniConvertor-2.0rc4\dlls
  3. 将此“ dll”路径添加到系统路径。
  4. 关闭VSCode(或其他编辑器),然后重新打开项目。
  5. 尝试再次运行代码。 享受吧!