使用 Pyinstaller 发布打包
Issue packaging with Pyinstaller
致所有专家 - 我们一直在开发包含以下模块的应用程序:
- opencv
- numpy
- pandas
- 跺脚
- nltk
- bs4
- 太平船
- 请求
和其他一些不属于 python 标准库的部分。希望将其打包成单个可执行文件。因此尝试使用 pyinstaller。执行时相同 - 它会建立分发文件夹 - 但无法执行。它抛出以下错误:
Traceback (most recent call last):
File "app.py", line 6, in <module>
File "/root/Projects/BIUEngine/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "ProcessManager.py", line 7, in <module>
File "/root/Projects/BIUEngine/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "ProcessWorker.py", line 16, in <module>
File "/root/Projects/BIUEngine/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/cv2/__init__.py", line 3, in <module>
ImportError: numpy.core.multiarray failed to import
[3502] Failed to execute script app
下面是运行
时命令的输出
root@devserver:~/Projects/BIUEngine/src# pyinstaller app.py
113 INFO: PyInstaller: 3.4
114 INFO: Python: 3.6.7
116 INFO: Platform: Linux-4.4.0-131-generic-x86_64-with-Ubuntu-16.04-xenial
116 INFO: wrote /root/Projects/BIUEngine/src/app.spec
119 INFO: UPX is not available.
123 INFO: Extending PYTHONPATH with paths
['/root/Projects/BIUEngine/src', '/root/Projects/BIUEngine/src']
123 INFO: checking Analysis
123 INFO: Building Analysis because Analysis-00.toc is non existent
124 INFO: Initializing module dependency graph...
127 INFO: Initializing module graph hooks...
179 INFO: Analyzing base_library.zip ...
10300 INFO: running Analysis Analysis-00.toc
10357 INFO: Caching module hooks...
10381 INFO: Analyzing /root/Projects/BIUEngine/src/app.py
13258 INFO: Processing pre-find module path hook distutils
13297 INFO: distutils: retargeting to non-venv dir '/usr/lib/python3.6/distutils'
14908 INFO: Processing pre-safe import module hook setuptools.extern.six.moves
16017 INFO: Processing pre-find module path hook site
16044 INFO: site: retargeting to fake-dir '/root/Projects/BIUEngine/lib/python3.6/site-packages/PyInstaller/fake-modules'
18473 INFO: Processing pre-safe import module hook six.moves
32950 INFO: Processing pre-safe import module hook urllib3.packages.six.moves
55571 INFO: Loading module hooks...
55572 INFO: Loading module hook "hook-PIL.Image.py"...
56546 INFO: Loading module hook "hook-encodings.py"...
56688 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
56699 INFO: Excluding import 'tkinter'
56704 INFO: Import to be excluded not found: 'FixTk'
56704 INFO: Loading module hook "hook-distutils.py"...
56753 INFO: Loading module hook "hook-certifi.py"...
56755 INFO: Loading module hook "hook-sysconfig.py"...
56792 INFO: Loading module hook "hook-pytz.py"...
56989 INFO: Loading module hook "hook-nltk.py"...
57816 INFO: Loading module hook "hook-pkg_resources.py"...
58813 INFO: Processing pre-safe import module hook win32com
58976 INFO: Loading module hook "hook-PIL.py"...
58988 INFO: Import to be excluded not found: 'FixTk'
58988 INFO: Excluding import 'PySide'
58996 INFO: Removing import of PySide from module PIL.ImageQt
59000 INFO: Excluding import 'PyQt5'
59007 INFO: Removing import of PyQt5 from module PIL.ImageQt
59010 INFO: Excluding import 'PyQt4'
59018 INFO: Removing import of PyQt4 from module PIL.ImageQt
59025 INFO: Excluding import 'tkinter'
59036 INFO: Removing import of tkinter from module PIL.ImageTk
59038 INFO: Loading module hook "hook-xml.py"...
59040 INFO: Loading module hook "hook-pandas.py"...
60447 INFO: Loading module hook "hook-sqlite3.py"...
60607 INFO: Loading module hook "hook-numpy.py"...
60609 INFO: Loading module hook "hook-pycparser.py"...
61578 INFO: Loading module hook "hook-lib2to3.py"...
61616 INFO: Loading module hook "hook-cv2.py"...
61617 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
61619 INFO: Loading module hook "hook-setuptools.py"...
62934 INFO: Loading module hook "hook-pydoc.py"...
62936 INFO: Loading module hook "hook-numpy.core.py"...
63088 INFO: Looking for ctypes DLLs
63294 WARNING: library user32 required via ctypes not found
63399 INFO: Analyzing run-time hooks ...
63439 INFO: Including run-time hook 'pyi_rth_pkgres.py'
63458 INFO: Including run-time hook 'pyi_rth_nltk.py'
63463 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
63536 INFO: Looking for dynamic libraries
65726 INFO: Looking for eggs
65727 INFO: Python library not in binary dependencies. Doing additional searching...
65822 INFO: Using Python library /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
65882 INFO: Warnings written to /root/Projects/BIUEngine/src/build/app/warn-app.txt
66237 INFO: Graph cross-reference written to /root/Projects/BIUEngine/src/build/app/xref-app.html
66476 INFO: checking PYZ
66477 INFO: Building PYZ because PYZ-00.toc is non existent
66478 INFO: Building PYZ (ZlibArchive) /root/Projects/BIUEngine/src/build/app/PYZ-00.pyz
70637 INFO: Building PYZ (ZlibArchive) /root/Projects/BIUEngine/src/build/app/PYZ-00.pyz completed successfully.
70722 INFO: checking PKG
70722 INFO: Building PKG because PKG-00.toc is non existent
70722 INFO: Building PKG (CArchive) PKG-00.pkg
70837 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
70839 INFO: Bootloader /root/Projects/BIUEngine/lib/python3.6/site-packages/PyInstaller/bootloader/Linux-64bit/run
70840 INFO: checking EXE
70840 INFO: Building EXE because EXE-00.toc is non existent
70840 INFO: Building EXE from EXE-00.toc
70842 INFO: Appending archive to ELF section in EXE /root/Projects/BIUEngine/src/build/app/app
70967 INFO: Building EXE from EXE-00.toc completed successfully.
70981 INFO: checking COLLECT
70982 INFO: Building COLLECT because COLLECT-00.toc is non existent
70983 INFO: Building COLLECT COLLECT-00.toc
82471 INFO: Building COLLECT COLLECT-00.toc completed successfully.
任何人都可以帮助我解决问题吗?
ImportError: numpy.core.multiarray failed to import
错误因导致与 numpy 尝试导入特定平台共享库相关的崩溃而臭名昭著。几乎总是因为试图导入 错误的版本 或者根本找不到这些库。
可能您打包的可执行文件正试图从包外部导入一些框架并遇到某种版本不匹配。您很可能也在使用某种虚拟环境,例如 conda 或 virtualenv?
在无法访问机器的情况下,很难查明问题所在。我会尝试以下方法来收集有关该问题的更多信息:
尝试在另一台没有 python 或至少没有安装 numpy 的机器上 运行 你的可执行文件,看看会发生什么。
尝试在一台只安装了一个版本的 numpy 的机器上重新打包您的应用程序。
仔细调查 运行ning python -c 'import numpy; print(numpy.__version__); print(numpy.__file__)'
在环境中实际导入了哪个版本的 numpy,以及从中创建可执行文件可执行文件本身。
最后一步可以通过把
import numpy
import numpy
print(numpy.__version__)
print(numpy.__file__)
在您的 app.py 中作为第一行(即在崩溃之前查看输出)
感谢所有提供帮助的人。我还在其他地方发帖——感谢上帝——有人确实想出了一个解决方案来解决这个问题。它对我有用。他的建议是——我可能为机器中的各种版本安装了 2 个或更多不同的 numpy。一个用于 2.7,另一个用于 3.6,依此类推。他建议我删除其中任何一个并检查是否一切正常。它确实有一定的意义 - 所以我继续并清理了 2.7 / 3.6 中的所有 numpy 和其他根据需要为项目手动安装的包。 Post 那 - 我刚刚创建了一个虚拟机并重新安装了所需的软件包(以及 numpy)。
此外 - 确保 pyinstaller - 在构建时确实将 numpy.core.multiarray 视为隐藏导入。 (第二步 - 我过去已经尝试过)。
说什么 - 事情对我来说很有效。它不再给我它曾经为此放弃的错误。现在正在解决其他问题 - 但这个方法/机制肯定对我有用。
谢谢大家再次帮助我。爱你们。
致所有专家 - 我们一直在开发包含以下模块的应用程序:
- opencv
- numpy
- pandas
- 跺脚
- nltk
- bs4
- 太平船
- 请求
和其他一些不属于 python 标准库的部分。希望将其打包成单个可执行文件。因此尝试使用 pyinstaller。执行时相同 - 它会建立分发文件夹 - 但无法执行。它抛出以下错误:
Traceback (most recent call last):
File "app.py", line 6, in <module>
File "/root/Projects/BIUEngine/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "ProcessManager.py", line 7, in <module>
File "/root/Projects/BIUEngine/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "ProcessWorker.py", line 16, in <module>
File "/root/Projects/BIUEngine/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/cv2/__init__.py", line 3, in <module>
ImportError: numpy.core.multiarray failed to import
[3502] Failed to execute script app
下面是运行
时命令的输出root@devserver:~/Projects/BIUEngine/src# pyinstaller app.py
113 INFO: PyInstaller: 3.4
114 INFO: Python: 3.6.7
116 INFO: Platform: Linux-4.4.0-131-generic-x86_64-with-Ubuntu-16.04-xenial
116 INFO: wrote /root/Projects/BIUEngine/src/app.spec
119 INFO: UPX is not available.
123 INFO: Extending PYTHONPATH with paths
['/root/Projects/BIUEngine/src', '/root/Projects/BIUEngine/src']
123 INFO: checking Analysis
123 INFO: Building Analysis because Analysis-00.toc is non existent
124 INFO: Initializing module dependency graph...
127 INFO: Initializing module graph hooks...
179 INFO: Analyzing base_library.zip ...
10300 INFO: running Analysis Analysis-00.toc
10357 INFO: Caching module hooks...
10381 INFO: Analyzing /root/Projects/BIUEngine/src/app.py
13258 INFO: Processing pre-find module path hook distutils
13297 INFO: distutils: retargeting to non-venv dir '/usr/lib/python3.6/distutils'
14908 INFO: Processing pre-safe import module hook setuptools.extern.six.moves
16017 INFO: Processing pre-find module path hook site
16044 INFO: site: retargeting to fake-dir '/root/Projects/BIUEngine/lib/python3.6/site-packages/PyInstaller/fake-modules'
18473 INFO: Processing pre-safe import module hook six.moves
32950 INFO: Processing pre-safe import module hook urllib3.packages.six.moves
55571 INFO: Loading module hooks...
55572 INFO: Loading module hook "hook-PIL.Image.py"...
56546 INFO: Loading module hook "hook-encodings.py"...
56688 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
56699 INFO: Excluding import 'tkinter'
56704 INFO: Import to be excluded not found: 'FixTk'
56704 INFO: Loading module hook "hook-distutils.py"...
56753 INFO: Loading module hook "hook-certifi.py"...
56755 INFO: Loading module hook "hook-sysconfig.py"...
56792 INFO: Loading module hook "hook-pytz.py"...
56989 INFO: Loading module hook "hook-nltk.py"...
57816 INFO: Loading module hook "hook-pkg_resources.py"...
58813 INFO: Processing pre-safe import module hook win32com
58976 INFO: Loading module hook "hook-PIL.py"...
58988 INFO: Import to be excluded not found: 'FixTk'
58988 INFO: Excluding import 'PySide'
58996 INFO: Removing import of PySide from module PIL.ImageQt
59000 INFO: Excluding import 'PyQt5'
59007 INFO: Removing import of PyQt5 from module PIL.ImageQt
59010 INFO: Excluding import 'PyQt4'
59018 INFO: Removing import of PyQt4 from module PIL.ImageQt
59025 INFO: Excluding import 'tkinter'
59036 INFO: Removing import of tkinter from module PIL.ImageTk
59038 INFO: Loading module hook "hook-xml.py"...
59040 INFO: Loading module hook "hook-pandas.py"...
60447 INFO: Loading module hook "hook-sqlite3.py"...
60607 INFO: Loading module hook "hook-numpy.py"...
60609 INFO: Loading module hook "hook-pycparser.py"...
61578 INFO: Loading module hook "hook-lib2to3.py"...
61616 INFO: Loading module hook "hook-cv2.py"...
61617 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
61619 INFO: Loading module hook "hook-setuptools.py"...
62934 INFO: Loading module hook "hook-pydoc.py"...
62936 INFO: Loading module hook "hook-numpy.core.py"...
63088 INFO: Looking for ctypes DLLs
63294 WARNING: library user32 required via ctypes not found
63399 INFO: Analyzing run-time hooks ...
63439 INFO: Including run-time hook 'pyi_rth_pkgres.py'
63458 INFO: Including run-time hook 'pyi_rth_nltk.py'
63463 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
63536 INFO: Looking for dynamic libraries
65726 INFO: Looking for eggs
65727 INFO: Python library not in binary dependencies. Doing additional searching...
65822 INFO: Using Python library /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
65882 INFO: Warnings written to /root/Projects/BIUEngine/src/build/app/warn-app.txt
66237 INFO: Graph cross-reference written to /root/Projects/BIUEngine/src/build/app/xref-app.html
66476 INFO: checking PYZ
66477 INFO: Building PYZ because PYZ-00.toc is non existent
66478 INFO: Building PYZ (ZlibArchive) /root/Projects/BIUEngine/src/build/app/PYZ-00.pyz
70637 INFO: Building PYZ (ZlibArchive) /root/Projects/BIUEngine/src/build/app/PYZ-00.pyz completed successfully.
70722 INFO: checking PKG
70722 INFO: Building PKG because PKG-00.toc is non existent
70722 INFO: Building PKG (CArchive) PKG-00.pkg
70837 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
70839 INFO: Bootloader /root/Projects/BIUEngine/lib/python3.6/site-packages/PyInstaller/bootloader/Linux-64bit/run
70840 INFO: checking EXE
70840 INFO: Building EXE because EXE-00.toc is non existent
70840 INFO: Building EXE from EXE-00.toc
70842 INFO: Appending archive to ELF section in EXE /root/Projects/BIUEngine/src/build/app/app
70967 INFO: Building EXE from EXE-00.toc completed successfully.
70981 INFO: checking COLLECT
70982 INFO: Building COLLECT because COLLECT-00.toc is non existent
70983 INFO: Building COLLECT COLLECT-00.toc
82471 INFO: Building COLLECT COLLECT-00.toc completed successfully.
任何人都可以帮助我解决问题吗?
ImportError: numpy.core.multiarray failed to import
错误因导致与 numpy 尝试导入特定平台共享库相关的崩溃而臭名昭著。几乎总是因为试图导入 错误的版本 或者根本找不到这些库。
可能您打包的可执行文件正试图从包外部导入一些框架并遇到某种版本不匹配。您很可能也在使用某种虚拟环境,例如 conda 或 virtualenv?
在无法访问机器的情况下,很难查明问题所在。我会尝试以下方法来收集有关该问题的更多信息:
尝试在另一台没有 python 或至少没有安装 numpy 的机器上 运行 你的可执行文件,看看会发生什么。
尝试在一台只安装了一个版本的 numpy 的机器上重新打包您的应用程序。
仔细调查 运行ning
python -c 'import numpy; print(numpy.__version__); print(numpy.__file__)'
在环境中实际导入了哪个版本的 numpy,以及从中创建可执行文件可执行文件本身。
最后一步可以通过把
import numpy
import numpy
print(numpy.__version__)
print(numpy.__file__)
在您的 app.py 中作为第一行(即在崩溃之前查看输出)
感谢所有提供帮助的人。我还在其他地方发帖——感谢上帝——有人确实想出了一个解决方案来解决这个问题。它对我有用。他的建议是——我可能为机器中的各种版本安装了 2 个或更多不同的 numpy。一个用于 2.7,另一个用于 3.6,依此类推。他建议我删除其中任何一个并检查是否一切正常。它确实有一定的意义 - 所以我继续并清理了 2.7 / 3.6 中的所有 numpy 和其他根据需要为项目手动安装的包。 Post 那 - 我刚刚创建了一个虚拟机并重新安装了所需的软件包(以及 numpy)。
此外 - 确保 pyinstaller - 在构建时确实将 numpy.core.multiarray 视为隐藏导入。 (第二步 - 我过去已经尝试过)。
说什么 - 事情对我来说很有效。它不再给我它曾经为此放弃的错误。现在正在解决其他问题 - 但这个方法/机制肯定对我有用。
谢谢大家再次帮助我。爱你们。