我有一个名为api.py的脚本,我想使用pyinstaller变成一个python应用程序。
当我从sublime文本中运行它时,下面的函数有效,但是当我尝试使用pyinstaller将其转换为unix可执行应用程序时,该应用程序不起作用。 Pyinstaller只有在我不导入zerorpc时才有效。
api.py
import zerorpc
class CalcApi(object):
def echo(self, text):
return text
def main():
addr = 'tcp://127.0.0.1:4242'
s = zerorpc.Server(CalcApi())
s.bind(addr)
s.run()
if __name__ == '__main__':
main()
运行以下命令后,我收到以下错误:
pyinstaller api.py -F
双击unix可执行文件后出现错误
Traceback (most recent call last):
File "api.py", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "site-packages/zerorpc/__init__.py", line 29, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "site-packages/zerorpc/context.py", line 32, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "site-packages/zerorpc/gevent_zmq.py", line 28, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "site-packages/zmq/__init__.py", line 34, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "site-packages/zmq/backend/__init__.py", line 40, in <module>
File "site-packages/zmq/backend/__init__.py", line 27, in <module>
File "site-packages/zmq/backend/select.py", line 26, in select_backend
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "site-packages/zmq/backend/cython/__init__.py", line 6, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 687, in load_module
module = imp.load_module(fullname, fp, filename, ext_tuple)
ImportError: dlopen(/var/folders/4q/kg5l33pj35lcgk6sf0d29hjr0000gn/T/_MEIvAkech/zmq.backend.cython.error.so, 2): Symbol not found: _zmq_errno
Referenced from: /var/folders/4q/kg5l33pj35lcgk6sf0d29hjr0000gn/T/_MEIvAkech/zmq.backend.cython.error.so
Expected in: flat namespace
in /var/folders/4q/kg5l33pj35lcgk6sf0d29hjr0000gn/T/_MEIvAkech/zmq.backend.cython.error.so
[914] Failed to execute script api
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
此外,这是运行pyinstaller api.py
后的日志59 INFO: PyInstaller: 3.3.1
59 INFO: Python: 2.7.13
65 INFO: Platform: Darwin-15.6.0-x86_64-i386-64bit
65 INFO: wrote /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/api.spec
72 INFO: UPX is not available.
73 INFO: Extending PYTHONPATH with paths
['/Users/username_test/Desktop/test/electron-python-example/pycalc/api_test',
'/Users/username_test/Desktop/test/electron-python-example/pycalc/api_test']
73 INFO: checking Analysis
73 INFO: Building Analysis because out00-Analysis.toc is non existent
73 INFO: Initializing module dependency graph...
75 INFO: Initializing module graph hooks...
130 INFO: running Analysis out00-Analysis.toc
140 INFO: Caching module hooks...
146 INFO: Analyzing /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/api.py
3237 INFO: Processing pre-safe import module hook _xmlplus
3370 INFO: Processing pre-find module path hook distutils
5111 INFO: Processing pre-find module path hook site
5111 INFO: site: retargeting to fake-dir '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/fake-modules'
6135 INFO: Loading module hooks...
6136 INFO: Loading module hook "hook-distutils.py"...
6137 INFO: Loading module hook "hook-sysconfig.py"...
6137 INFO: Loading module hook "hook-xml.py"...
6201 INFO: Loading module hook "hook-zmq.py"...
6518 INFO: Excluding import 'zmq.libzmq'
6519 INFO: Removing import of zmq.libzmq from module zmq
6520 INFO: Loading module hook "hook-pycparser.py"...
6717 INFO: Loading module hook "hook-httplib.py"...
6719 INFO: Loading module hook "hook-encodings.py"...
7148 INFO: Loading module hook "hook-_tkinter.py"...
7153 INFO: checking Tree
7154 INFO: Building Tree because out00-Tree.toc is non existent
7154 INFO: Building Tree out00-Tree.toc
7206 INFO: checking Tree
7206 INFO: Building Tree because out01-Tree.toc is non existent
7206 INFO: Building Tree out01-Tree.toc
7228 INFO: Loading module hook "hook-pkg_resources.py"...
7451 INFO: Processing pre-safe import module hook win32com
7654 INFO: Loading module hook "hook-gevent.monkey.py"...
7662 INFO: Loading module hook "hook-setuptools.py"...
10546 INFO: Loading module hook "hook-numpy.core.py"...
10663 INFO: Loading module hook "hook-pydoc.py"...
10665 INFO: Excluding import 'Tkinter'
10666 INFO: Removing import of Tkinter from module pydoc
10686 INFO: Looking for ctypes DLLs
10736 INFO: Analyzing run-time hooks ...
10741 INFO: Including run-time hook 'pyi_rth__tkinter.py'
10745 INFO: Including run-time hook 'pyi_rth_pkgres.py'
10748 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
10761 INFO: Looking for dynamic libraries
11059 INFO: Looking for eggs
11059 INFO: Using Python library /Library/Frameworks/Python.framework/Versions/2.7/Python
11065 INFO: Warnings written to /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/build/api/warnapi.txt
11114 INFO: Graph cross-reference written to /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/build/api/xref-api.html
11330 INFO: checking PYZ
11330 INFO: Building PYZ because out00-PYZ.toc is non existent
11330 INFO: Building PYZ (ZlibArchive) /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/build/api/out00-PYZ.pyz
12109 INFO: Building PYZ (ZlibArchive) /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/build/api/out00-PYZ.pyz completed successfully.
12255 INFO: checking PKG
12255 INFO: Building PKG because out00-PKG.toc is non existent
12255 INFO: Building PKG (CArchive) out00-PKG.pkg
18776 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
18852 INFO: Bootloader /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller/bootloader/Darwin-64bit/run
18852 INFO: checking EXE
18852 INFO: Building EXE because out00-EXE.toc is non existent
18852 INFO: Building EXE from out00-EXE.toc
18852 INFO: Appending archive to EXE /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/dist/api
18874 INFO: Fixing EXE for code signing /Users/username_test/Desktop/test/electron-python-example/pycalc/api_test/dist/api
18878 INFO: Building EXE from out00-EXE.toc completed successfully
这也是我的api.spec文件
# -*- mode: python -*-
block_cipher = None
a = Analysis(['api.py'],
pathex=['/Users/username_test/Desktop/test/electron-python-example/pycalc/api_test'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='api',
debug=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )
我重新安装了所有内容并升级了包括zerorpc和pyinstaller在内的所有软件包无济于事