Pyinstaller 找不到合适的图像
Pyinstaller no suitable image found
我的系统上安装了 PyInstaller 4.0 版。我正在尝试使用 python 3.7.3 构建一个 python 脚本。此 python 脚本导入其他 python 脚本,这些脚本有自己的导入语句。
我正在使用命令构建:
pyinstaller --noconfirm --clean script_to_build.py
但是,当我 运行 构建新的二进制文件时,出现以下错误:
构建文件后,在 dist 文件夹中有一个包含两个文件的 Foundation 文件夹,_Foundation.cpython-37m-darwin.so 和 _inlines.cpython-37m-darwin.so,但它还在抱怨缺少 Foundation 库。此错误消息是什么意思,我该如何解决?
Traceback (most recent call last):
File "PyInstaller/loader/pyiboot01_bootstrap.py", line 144, in __init__
File "ctypes/__init__.py", line 348, in __init__
OSError: dlopen(./dist/script_to_build/Foundation, 6): no suitable image found. Did find:
./dist/script_to_build/Foundation: not a file
./dist/script_to_build/Foundation: not a file
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "script_to_build.py", line 66, in <module>
import script1
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/Library/Python/3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "script1.py", line 19, in <module>
import pyautogui
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/Library/Python/3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "pyautogui/__init__.py", line 241, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/Library/Python/3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "mouseinfo/__init__.py", line 100, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/Library/Python/3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "rubicon/objc/__init__.py", line 15, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/Library/Python/3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "rubicon/objc/runtime.py", line 89, in <module>
File "rubicon/objc/runtime.py", line 66, in load_library
File "PyInstaller/loader/pyiboot01_bootstrap.py", line 146, in __init__
__main__.PyInstallerImportError: Failed to load dynlib/dll './dist/script_to_build/Foundation'. Most probably this dynlib/dll was not found when the application was frozen.
终于想通了。这是有效的更新命令:
pyinstaller --add-binary "/System/Library/Frameworks/Foundation.framework/Versions/C/Resources/BridgeSupport/Foundation.dylib:." --onefile --noconfirm --clean script_to_build.py
我可以用这个编译程序,但是在执行二进制文件时出现错误“../../../../../../../../. ./Library/Python/3.7m/include/pyconfig.h 无法提取!”为了修复这个错误,我不得不修改函数 relpath_to_config_or_make(filename)
file /Lirary/Python/3.7/site-packages/PyInstaller/utils/hooks/init.py 如下:
def relpath_to_config_or_make(filename):
"""
The following is refactored out of hook-sysconfig and hook-distutils,
both of which need to generate "datas" tuples for pyconfig.h and
Makefile, under the same conditions.
"""
# Relative path in the dist directory.
prefix = _find_prefix(filename)
rel_path = os.path.relpath(os.path.dirname(filename), prefix)
if '../' in rel_path and is_darwin:
new_path = os.path.relpath(os.path.abspath(rel_path), os.path.expanduser('~'))
else:
new_path = os.path.relpath(os.path.dirname(filename), prefix)
return new_path
我的系统上安装了 PyInstaller 4.0 版。我正在尝试使用 python 3.7.3 构建一个 python 脚本。此 python 脚本导入其他 python 脚本,这些脚本有自己的导入语句。
我正在使用命令构建:
pyinstaller --noconfirm --clean script_to_build.py
但是,当我 运行 构建新的二进制文件时,出现以下错误:
构建文件后,在 dist 文件夹中有一个包含两个文件的 Foundation 文件夹,_Foundation.cpython-37m-darwin.so 和 _inlines.cpython-37m-darwin.so,但它还在抱怨缺少 Foundation 库。此错误消息是什么意思,我该如何解决?
Traceback (most recent call last):
File "PyInstaller/loader/pyiboot01_bootstrap.py", line 144, in __init__
File "ctypes/__init__.py", line 348, in __init__
OSError: dlopen(./dist/script_to_build/Foundation, 6): no suitable image found. Did find:
./dist/script_to_build/Foundation: not a file
./dist/script_to_build/Foundation: not a file
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "script_to_build.py", line 66, in <module>
import script1
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/Library/Python/3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "script1.py", line 19, in <module>
import pyautogui
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/Library/Python/3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "pyautogui/__init__.py", line 241, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/Library/Python/3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "mouseinfo/__init__.py", line 100, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/Library/Python/3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "rubicon/objc/__init__.py", line 15, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "/Library/Python/3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "rubicon/objc/runtime.py", line 89, in <module>
File "rubicon/objc/runtime.py", line 66, in load_library
File "PyInstaller/loader/pyiboot01_bootstrap.py", line 146, in __init__
__main__.PyInstallerImportError: Failed to load dynlib/dll './dist/script_to_build/Foundation'. Most probably this dynlib/dll was not found when the application was frozen.
终于想通了。这是有效的更新命令:
pyinstaller --add-binary "/System/Library/Frameworks/Foundation.framework/Versions/C/Resources/BridgeSupport/Foundation.dylib:." --onefile --noconfirm --clean script_to_build.py
我可以用这个编译程序,但是在执行二进制文件时出现错误“../../../../../../../../. ./Library/Python/3.7m/include/pyconfig.h 无法提取!”为了修复这个错误,我不得不修改函数 relpath_to_config_or_make(filename)
file /Lirary/Python/3.7/site-packages/PyInstaller/utils/hooks/init.py 如下:
def relpath_to_config_or_make(filename):
"""
The following is refactored out of hook-sysconfig and hook-distutils,
both of which need to generate "datas" tuples for pyconfig.h and
Makefile, under the same conditions.
"""
# Relative path in the dist directory.
prefix = _find_prefix(filename)
rel_path = os.path.relpath(os.path.dirname(filename), prefix)
if '../' in rel_path and is_darwin:
new_path = os.path.relpath(os.path.abspath(rel_path), os.path.expanduser('~'))
else:
new_path = os.path.relpath(os.path.dirname(filename), prefix)
return new_path