我正在尝试使用pyinstaller将python代码编译为.exe文件。 使用以下代码将产生可用的.exe文件,且不会出现错误消息:
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QMainWindow()
window.show()
print('app loaded')
sys.exit(app.exec_())
但是,一旦我添加:
from scipy.integrate import solve_ivp
对于导入语句,我收到错误消息“无法执行脚本”。
在命令窗口中执行pyinstaller的过程中,我还看到以下内容:“警告:无法找到Qt5翻译”以及包括Matplotlib模块在内的一些警告。
我尝试将PyQt5\Qt\plugins\platforms
文件夹复制到保存.exe文件的文件夹,并按照另一个问题的建议,将Anaconda3 \ Library \ plugins添加为环境变量QT_PLUGIN_PATH
,但两个建议的解决方案均不起作用。
当我尝试从命令窗口执行程序时,出现错误消息:“ ImportError:DLL加载失败”
对于此问题的任何帮助将不胜感激。
编辑:
我尝试了oetzi的主张,并专门为我的项目创建了一个新的anaconda环境。我安装了scipy,numpy,matplotlib和pyqt的模块,并在该新环境中安装了pyinstaller。这次我在Anaconda Prompt中键入了命令。同样,没有scipy.integrate.solve_ivp,它也可以正常工作。有了它,当我尝试运行pyinstaller时出现以下错误。
18881 WARNING: Cannot read QLibraryInfo output: raised Expecting value: line 1 column 1 (char 0) when decoding:
False
Traceback (most recent call last):
File "C:\Users\domin\Anaconda3\envs\testenv\Scripts\pyinstaller-script.py", line 10, in <module>
sys.exit(run())
File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\build_main.py", line 844, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\build_main.py", line 791, in build
exec(code, spec_namespace)
File "C:\Users\domin\polybox\ETH\Master Thesis\PycharmProjects\Perfusion Simulation\Pyinstaller\test\test.spec", line 17, in <module>
noarchive=False)
File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\build_main.py", line 243, in __init__
self.__postinit__()
File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
self.assemble()
File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\build_main.py", line 502, in assemble
module_hook.post_graph()
File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\imphook.py", line 410, in post_graph
self._load_hook_module()
File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\building\imphook.py", line 377, in _load_hook_module
self.hook_module_name, self.hook_filename)
File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\compat.py", line 793, in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>", line 407, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 907, in load_module
File "<frozen importlib._bootstrap_external>", line 732, in load_module
File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
File "<frozen importlib._bootstrap>", line 696, in _load
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\hooks\hook-PySide2.py", line 18, in <module>
collect_system_data_files(pyside2_library_info.location['PrefixPath'],
File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 87, in __getattr__
return getattr(self, name)
File "C:\Users\domin\Anaconda3\envs\testenv\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 89, in __getattr__
raise AttributeError
AttributeError
答案 0 :(得分:0)
好的,我现在要做的就是完全卸载并重新安装所有内容。之后,我只添加了所需的模块,即scipy,numpy,matplotlib,pyqt5和pyinstaller。之后,一切正常。我的猜测是,由于我同时安装了PyQt5和PyQt4,因此它弄乱了模块。现在我只安装了PyQt5,一切正常。