使用pyinstaller捆绑pycups时出现Image Not Found错误

时间:2016-07-07 14:26:58

标签: python macos pyinstaller

我正在尝试使用pyinstaller从python文件创建一个单文件可执行文件。尝试import cups时,可执行文件失败,并出现以下错误:

Failed to execute script ImportPyCups
Traceback (most recent call last):
File "ImportPyCups.py", line 1, in <module>
  import cups
File "/Library/Python/2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
  exec(bytecode, module.__dict__)
File "build/bdist.macosx-10.8-intel/egg/cups.py", line 7, in <module>
File "build/bdist.macosx-10.8-intel/egg/cups.py", line 6, in __bootstrap__
ImportError: dlopen(/var/folders/jp/8v0hvshd585dw9v_7bnlxsqh0000gn/T/_MEILQoRVs/cups.so, 2): image not found

这是python文件(是的,只是一个导入语句):

import cups

以下是我将python文件转换为单个文件可执行文件的命令:

$ /usr/local/bin/pyi-makespec --onefile --console ImportPyCups.py
$ pyinstaller ImportPyCups.spec
然后我跑了:

$ dist/ImportPyCups

这是我收到上面粘贴的错误消息的地方。如果我只是从终端运行python文件,如下所示,不会发生错误:

$ python ImportPyCups.py

它运行的环境是(Mac OS X 10.8.5):

PyInstaller: 3.2
Python: 2.7.2
Platform: Darwin-12.5.0-x86_64-i386-64bit

安装的pycups是:

Metadata-Version: 1.0
Name: pycups
Version: 1.9.68
Summary: Python bindings for libcups
Home-page: http://cyberelk.net/tim/software/pycups/
Author: Tim Waugh
Author-email: twaugh@redhat.com
License: GPLv2+
Location: /Library/Python/2.7/site-packages/pycups-1.9.68-py2.7-macosx-10.8-intel.egg
Requires: 
Classifiers:
  Intended Audience :: Developers
  Topic :: Software Development :: Libraries :: Python Modules
  License :: OSI Approved :: GNU General Public License (GPL)
  Development Status :: 5 - Production/Stable
  Operating System :: Unix
  Programming Language :: C
  Programming Language :: Python
  Programming Language :: Python :: 2
  Programming Language :: Python :: 3

从错误消息中看起来似乎缺少某些东西,但我无法弄清楚是什么。

1 个答案:

答案 0 :(得分:0)

我终于找到了答案:https://github.com/pyinstaller/pyinstaller/issues/1728

如果您使用easy_install安装PyCups,您将获得一个.egg文件。 Pyinstaller不会在压缩的.egg文件中查找C扩展名,也永远不会。 解决方案很简单:删除.egg文件并使用pip安装PyCup。

这不是特定于PyCups,而是easy_install。