image2gif 的 Python 导入问题

标签 python pip

我知道我已经安装了所有包(pip freeze) 我在 Windows 10 机器上运行 python3.4,但遇到奇怪的依赖问题

测试.py:

from images2gif import writeGif
from PIL import Image, ImageSequence
import os

file_names = ['output\donkey-1.png', 'output\donkey-2.png']

images = [Image.open(fn) for fn in file_names]

size = (600,350)
for im in images:
    im.thumbnail(size, Image.ANTIALIAS)

filename = "test.gif"
writeGif(filename, images, duration=0.5, subRectangles=False)

运行 test.py 出现以下错误,无法在网络上的其他任何地方找到此错误

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    from images2gif import writeGif
  File "C:\Python34\lib\site-packages\images2gif\__init__.py", line 1, in <module>
    from images2gif import readGif as readGif
ImportError: cannot import name 'readGif'

最佳答案

我刚刚查看了 actual repository source code : 它使用 Python 2 风格的相对导入。也就是说,images2gif 不支持开箱即用的 Python 3。

目前的一个解决方案可能是下载 the sourcefile from pypi ,提取它(不确定 Windows 是否喜欢 tar.gz 文件),cd 进入目录并在其上运行 2to3:

2to3 -w .

然后手动安装:

python3.4 setup.py install

但可能更简单,只需查看 2to3 的结果:手动更改已安装包中的两个导入语句(在 __init__.py 中):

-from images2gif import readGif as readGif
-from images2gif import writeGif as writeGif
+from .images2gif import readGif as readGif
+from .images2gif import writeGif as writeGif

因为看起来其他一切都与 PY3K 兼容;这两个导入语句中 images2gif 前面的 pip 使其成为正确的 PY3K 相对导入。

关于image2gif 的 Python 导入问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32674597/

相关文章:

python - pip force reinstall in requirements.txt

python - Pip 安装 - 下载的 whl 文件会保留并占用磁盘空间吗?

python - 不同数据框列中的 zip 列表元素

python - 在 A[i] 之前的 100 万个项目中,有多少项目小于 A[i]?

python - 将不同版本(python 2.7 vs 3.5)上传到 PyPI

python - 无法再使用 pip 安装旧版本

python - 在linux上安装cassandra驱动程序,以便我可以从python连接到cassandra

python - chrome 和 flask 的超时问题

python - WALS Model Tensorflow - 为新用户获取推荐

python - 有没有办法更新一个包,并递归地更新它使用的所有包?