[英]How do I make exe file with torch module by using pyinstaller?
[Environment] [环境]
I successfully ran main_for_exe.py in vscode.我在 vscode 中成功运行了 main_for_exe.py。
When I make exe file using pyinstaller and then ran exe file, however, I have the below error message.但是,当我使用 pyinstaller 制作 exe 文件然后运行 exe 文件时,出现以下错误消息。
enter image description here在此处输入图像描述
There were some solutions: "add module to hiddenimports"有一些解决方案:“将模块添加到 hiddenimports”
enter image description here在此处输入图像描述
but, it does not work.但是,它不起作用。
Basic modules of python such as "os" and "sys" are successfully loaded, but "No module named numpy" error message appeared. python“os”、“sys”等基本模块加载成功,但出现“No module named numpy”错误信息。 So, I think that modules installed by 'pip' and 'conda' aren't loaded.
因此,我认为未加载“pip”和“conda”安装的模块。
How do I solve this?我该如何解决这个问题?
No matter base
or other virtual conda environments, we need to first activate it then with the command pip install
executed in integrated Terminal, the module can get its right location, or it will throw No module error.无论是
base
还是其他虚拟conda环境,我们都需要先激活,然后在集成终端执行命令pip install
,模块才能得到正确的位置,否则会抛出No module错误。
Now open your project in VS Code, after activating anaconda environment, run pip show numpy
to check if its location is anaconda\lib\site-packages
.现在在 VS Code 中打开你的项目,激活 anaconda 环境后,运行
pip show numpy
检查它的位置是否是anaconda\lib\site-packages
。 If not, please reinstall it, then regenerate.exe, the error should go away.如果不行,请重新安装,然后regenerate.exe,错误应该go消失。
Reference: Select and activate Environment .参考: Select 并激活环境。
I solved this problem!我解决了这个问题!
I just upgraded the pyinstaller package.我刚刚升级了pyinstaller package。
It seems that the pyinstaller package, before upgrade, cannot find the site-package path where the modules installed by anaconda are located.看来pyinstaller package升级前找不到anaconda安装的模块所在的site-package路径。 (Generally site-packe path: "~/anaconda3/lib/site-packages")
(一般站点包路径:“~/anaconda3/lib/site-packages”)
In this case, there are two solutions.在这种情况下,有两种解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.