我在Ubuntu上使用Pyinstaller为我的Python代码创建二进制可执行文件。此代码包含大量文件和依赖项。其中一个是tensorflow
。可执行文件正在正确创建,但是当我尝试运行它时,我收到以下错误:
Traceback (most recent call last):
File "detection_init.py", line 14, in <module>
import lib.tensorboxDetector as tensorboxDetector
File "/tmp/pip-build-EuLWEf/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
File "lib/tensorboxDetector.py", line 20, in <module>
import tensorflow as tf
File "/tmp/pip-build-EuLWEf/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
File "tensorflow/__init__.py", line 24, in <module>
File "/tmp/pip-build-EuLWEf/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
File "tensorflow/python/__init__.py", line 104, in <module>
File "/tmp/pip-build-EuLWEf/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
File "tensorflow/python/platform/test.py", line 57, in <module>
File "/tmp/pip-build-EuLWEf/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
File "mock/__init__.py", line 2, in <module>
File "/tmp/pip-build-EuLWEf/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
File "mock/mock.py", line 71, in <module>
File "pbr/version.py", line 461, in semantic_version
File "pbr/version.py", line 447, in _get_version_from_pkg_resources
File "/tmp/pip-build-EuLWEf/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
File "pbr/packaging.py", line 32, in <module>
File "/tmp/pip-build-EuLWEf/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
File "setuptools/__init__.py", line 160, in <module>
File "setuptools/monkey.py", line 104, in patch_all
File "setuptools/monkey.py", line 156, in patch_for_msvc_specialized_compiler
File "importlib/__init__.py", line 37, in import_module
ImportError: No module named msvc
如何解决此错误并正确运行文件?
答案 0 :(得分:0)
我将msvc添加到隐藏的导入中。我仍然在与进口作斗争,但似乎已经通过了这个。
{
a = Analysis(['/Users/Ben/Documents/DeepMeerkat/DeepMeerkat/main.py'],
pathex=['/Users/ben/Documents/DeepMeerkat/DeepMeerkat/'],
binaries=[],
datas=[],
hiddenimports=['setuptools.msvc'],
hookspath=[],
runtime_hooks=[],
excludes=[ 'enchant', 'twisted'],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
}
答案 1 :(得分:0)
使用Pyinstaller的开发版本解决了这个问题。更多详情:https://github.com/pyinstaller/pyinstaller/issues/2824