I'm trying to create a one-file executable from a python file using pyinstaller. The executable fails when trying to import cups
and gives the following error:
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
Here's the python file (yes, just a single import statement):
import cups
Here are the commands I run to turn the python file into a single file executable:
$ /usr/local/bin/pyi-makespec --onefile --console ImportPyCups.py
$ pyinstaller ImportPyCups.spec
I then run:
$ dist/ImportPyCups
This is where I get the error message that I pasted above. If I just run the python file from the terminal like below, no errors occur:
$ python ImportPyCups.py
The environment this runs in is (Mac OS X 10.8.5):
PyInstaller: 3.2
Python: 2.7.2
Platform: Darwin-12.5.0-x86_64-i386-64bit
The installed pycups is:
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
From the error message it seems that something is missing, but I haven't been able to figure out what.
I've finally found the answer here: https://github.com/pyinstaller/pyinstaller/issues/1728
If you use easy_install to install PyCups, you'll get an .egg file. Pyinstaller doesn't look for C extensions inside zipped .egg files and never will. The solution is simple: Remove the .egg file and install PyCups using pip.
This is not specific to PyCups, but to easy_install.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.