首页 > 解决方案 > Python Wand 缺少库/路径

问题描述

我正在尝试为 Python 3 安装 Wand,对我来说,可以通过我的 Cygwin 安装访问它。

我首先尝试安装 Wand:

# Install Wand
#--------------
# https://docs.wand-py.org/en/0.6.6/guide/install.html
$ python -m pip install Wand
Defaulting to user installation because normal site-packages is not writeable
Collecting Wand
  Downloading Wand-0.6.6-py2.py3-none-any.whl (138 kB)
     |████████████████████████████████| 138 kB 1.5 MB/s
Installing collected packages: Wand
Successfully installed Wand-0.6.6
WARNING: You are using pip version 21.0; however, version 21.0.1 is available.
You should consider upgrading via the '/bin/python -m pip install --upgrade pip' command.

然后我尝试导入 Image 但出现错误:

# Try importing from Wand
#------------------------
# https://docs.wand-py.org/en/0.6.6/guide/read.html#open-an-image-file
$ python
>>> from wand.image import Image
Traceback (most recent call last):
  File "/home/User.Name/.local/lib/python3.8/site-packages/wand/api.py", line 151, in <module>
    libraries = load_library()
  File "/home/User.Name/.local/lib/python3.8/site-packages/wand/api.py", line 140, in load_library
    raise IOError('cannot find library; tried paths: ' + repr(tried_paths))
OSError: cannot find library; tried paths: []

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/User.Name/.local/lib/python3.8/site-packages/wand/image.py", line 18, in <module>
    from . import assertions
  File "/home/User.Name/.local/lib/python3.8/site-packages/wand/assertions.py", line 155, in <module>
    from .color import Color  # noqa: E402
  File "/home/User.Name/.local/lib/python3.8/site-packages/wand/color.py", line 10, in <module>
    from .api import library
  File "/home/User.Name/.local/lib/python3.8/site-packages/wand/api.py", line 175, in <module>
    raise ImportError('MagickWand shared library not found.\n'
ImportError: MagickWand shared library not found.
You probably had not installed ImageMagick library.
Try to install:
  https://docs.wand-py.org/en/latest/guide/install.html

引用的安装页面的内容与我上面使用的安装页面相同。

有人可以建议下一步尝试吗?

谢谢。


故障排除

检查我是否安装了 Magick[Wand] 库:

# Check what Wand/Magick things are installed
#--------------------------------------------
$ cygcheck -c -d | sed -n -e '/[Ww]and/p' -e '/[Mm]agick/p' | sort -u
ImageMagick                         7.0.10.27-2
libGraphicsMagick++12               1.3.36-2
libGraphicsMagick3                  1.3.36-2
libGraphicsMagickWand2              1.3.36-2
libMagickC++6_8                     6.9.10.11-4
libMagickCore6_6                    6.9.10.11-4
libMagickCore7_7                    7.0.10.27-2
libMagickWand6_6                    6.9.10.11-4
libMagickWand7_7                    7.0.10.27-2

确认安装魔杖:

$ls -l ~/.local/lib/python3.8/site-packages/*
/home/User.Name/.local/lib/python3.8/site-packages/wand:
total 601
-rw-------  1 User.Name None    202 2021-04-18 01:04 __init__.py
drwx------+ 1 User.Name None      0 2021-04-18 01:04 __pycache__/
-rw-------  1 User.Name None   9844 2021-04-18 01:04 api.py
-rw-------  1 User.Name None   4721 2021-04-18 01:04 assertions.py
drwx------+ 1 User.Name None      0 2021-04-18 01:04 cdefs/
-rw-------  1 User.Name None  24508 2021-04-18 01:04 color.py
-rw-------  1 User.Name None   4570 2021-04-18 01:04 compat.py
-rw-------  1 User.Name None   2449 2021-04-18 01:04 display.py
-rw-------  1 User.Name None  77010 2021-04-18 01:04 drawing.py
-rw-------  1 User.Name None  11165 2021-04-18 01:04 exceptions.py
-rw-------  1 User.Name None   4021 2021-04-18 01:04 font.py
-rw-------  1 User.Name None 412660 2021-04-18 01:04 image.py
-rw-------  1 User.Name None  11663 2021-04-18 01:04 resource.py
-rw-------  1 User.Name None  13183 2021-04-18 01:04 sequence.py
-rw-------  1 User.Name None  10453 2021-04-18 01:04 version.py

/home/User.Name/.local/lib/python3.8/site-packages/Wand-0.6.6.dist-info:
total 15
-rw------- 1 User.Name None    4 2021-04-18 01:04 INSTALLER
-rw------- 1 User.Name None 1183 2021-04-18 01:04 LICENSE
-rw------- 1 User.Name None 3850 2021-04-18 01:04 METADATA
-rw------- 1 User.Name None 3406 2021-04-18 01:04 RECORD
-rw------- 1 User.Name None    0 2021-04-18 01:04 REQUESTED
-rw------- 1 User.Name None    5 2021-04-18 01:04 top_level.txt
-rw------- 1 User.Name None  110 2021-04-18 01:04 WHEEL

文件的时间戳与安装的大致时间相匹配。

确认sys.path包括~/.local/lib/python3.8/site-packages

$ python
>>> import sys
>>> for path in sys.path:
...    print(path)
... 

/usr/lib/python38.zip
/usr/lib/python3.8
/usr/lib/python3.8/lib-dynload
/home/User.Name/.local/lib/python3.8/site-packages
/usr/lib/python3.8/site-packages

标签: python-3.xwand

解决方案


这个答案可能会有所帮助:

https://stackoverflow.com/a/26088037/2090942

检查系统上的 python 版本是 32 位还是 64 位。如果您有 32 位版本,请尝试安装 64 位版本,然后检查。


推荐阅读