我使用pyinstaller从python脚本创建了一个exe。 该脚本依赖于张量流。该程序包完美创建。 问题是当我运行exe时。
Python 3.6.5 Pyinstaller 3.3.1 构建平台:Win 8.1 64bit 运行平台Win 7 64bit
C:\Program Files\test\FaceDetectionPackageBeta1\dist\FaceDetection>FaceDetection.exe
Using TensorFlow backend.
Traceback (most recent call last):
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14,
in swig_import_helper
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tensorflow.python._pywrap_tensorflow_inter
nal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <modu
le>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17,
in <module>
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16,
in swig_import_helper
File "importlib\__init__.py", line 126, in import_module
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 714, in load_module
ImportError: DLL load failed with error code -1073741795
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "TELFaceDetection.py", line 12, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\keras\__init__.py", line 3, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\keras\utils\__init__.py", line 6, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\keras\utils\conv_utils.py", line 9, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\keras\backend\__init__.py", line 89, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\tensorflow\__init__.py", line 24, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\tensorflow\python\__init__.py", line 49, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <modu
le>
ImportError: Traceback (most recent call last):
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14,
in swig_import_helper
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tensorflow.python._pywrap_tensorflow_inter
nal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <modu
le>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17,
in <module>
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16,
in swig_import_helper
File "importlib\__init__.py", line 126, in import_module
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 714, in load_module
ImportError: DLL load failed with error code -1073741795
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_probl
ems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
[4988] Failed to execute script TELFaceDetection
下面是规格文件
# -*- mode: python -*-
block_cipher = None
a = Analysis(['FaceDetection.py'],
pathex=['D:\\FaceDetectionSetup\\FaceDetectioPackageSource'],
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,
exclude_binaries=True,
name='FaceDetection',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='FaceDetection')
我已经尝试过link中的解决方案,但这也不起作用。当我执行exe时,未收到名为tensorflow.python.framework.load_library的模块错误。
如何设置路径,以便选择相对路径。 在Win 7 64位桌面系统上,同样的工作没有任何问题。因此,可以在一个系统上工作,而不能在另一个系统上工作。任何帮助表示感谢。
谢谢 -Megha
答案 0 :(得分:0)
if getattr(sys, 'frozen', False):
appPath = os.path.dirname(sys.executable)
else:
appPath = os.path.dirname(os.path.realpath(__file__))
使用此代码,您可以为可执行文件以及直接运行.py时指定应用程序目录路径变量。