我的系统上安装了PyInstaller 4.0版。我正在尝试使用python 3.7.3构建python脚本。此python脚本会导入其他具有自己的import语句的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.
答案 0 :(得分:0)
最后弄清楚了。这是有效的更新命令:
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)
文件/Lirary/Python/3.7/site-packages/PyInstaller/utils/hooks/init.py: / p>
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