运行pyinstaller应用程序时出现导入错误

4

我编写了一个使用以下技术的Python应用程序:

from PIL import Image

我想发布一个打包版本的应用程序,这样使用它的人就不需要安装所有的依赖项。为此,我使用了pyinstaller,但效果不太好。我运行了以下命令:pyinstaller --onefile image_download.py,没有报错。然而,当我运行应用程序时,出现以下错误信息:Traceback (most recent call last):File "", line 26, in File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_moduleexec(bytecode, module.dict)File "/home/ic/twitter-project/build/image_download/out00-PYZ.pyz/PIL.PngImagePlugin", line 40, in File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_moduleexec(bytecode, module.dict)File "/home/ic/twitter-project/build/image_download/out00-PYZ.pyz/PIL.Image", line 63, in ImportError: cannot import name _imaging。我正在使用Ubuntu 14.04、Python 2.7、pyinstaller 2.1和PIL.VERSION 1.1.7(尽管我认为我已经安装了Pillow 2.8.1)。脚本作为python image_download.py正常运行,但是由于某些原因,pyinstaller无法导入_imaging。有什么建议吗?

尝试将import _imaging添加到image_download.py的顶部并重新构建可执行文件……有时会错过奇怪的隐藏导入,它可能像import("_imaging")这样在某个地方导入。 - Joran Beasley
没有成功,没有这样的导入。我尝试使用 import PIL._imaging 和其他几个组合,但都没有成功。 - user2891462
请查看此答案 https://dev59.com/oY7ea4cB1Zd3GeqPAFoU#32418327 - Nizam Mohamed
1个回答

3

最终,我无法使用pyinstaller解决导入问题,因此放弃了这个方法。

不过,我使用Nuitkabbfreeze成功构建了一个独立的可执行文件。如果其他人遇到相同的问题,可以尝试使用其他工具。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接