简体   繁体   English

如何使用 pyinstaller 使用 torch 模块制作 exe 文件?

[英]How do I make exe file with torch module by using pyinstaller?

[Environment] [环境]

  • vscode代码
  • Anaconda Anaconda
  • Window Window

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.在这种情况下,有两种解决方案。

  1. First, you just upgrade pyinstaller.首先,您只需升级 pyinstaller。
  2. Second, you add site-package path to hookspath and then run "pyinstaller main.spec".其次,将站点包路径添加到 hookspath,然后运行“pyinstaller main.spec”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想使用 pyinstaller 将 .py 文件转换为 exe 文件 - I want to make .py file into exe file by using pyinstaller 如何在python中使用pyinstaller和sounddevice模块获取有效的EXE文件 - How to get a working EXE file using pyinstaller with the sounddevice module in Python 当我使用 Pyinstaller 将 .py 文件转换为 .exe 时,如何包含输出文件? - How do I include an output file when I convert a .py file to .exe using Pyinstaller? Python3 | 安装程序 | 如何将excel文件添加到exe - Python3 | Pyinstaller | how do I add an excel file to the exe 如何使用 pyinstaller 制作 vpython .exe - how to make vpython .exe using pyinstaller 使用pyinstaller spec文件制作python pypylon项目的exe文件 - Make exe file of python pypylon project using pyinstaller spec file 如何使用pyinstaller制作exe文件连接SQL Server并导出excel文件? - How to make an exe file to connect SQL Server and export excel file by using pyinstaller? 如何使用Pyinstaller在Windows上制作Mac文件? - How do I use Pyinstaller to make a Mac file on Windows? 如何在通过 pyinstaller 创建 exe 文件时包含 timzonefinder 模块 - How to include timzonefinder module while creating an exe file via pyinstaller 我试图通过pyinstaller制作.exe文件时遇到此错误-“ ModuleNotFoundError:没有名为'acrcloud_extr_tool'的模块” - I'm getting this error when I'm trying to make an .exe file through pyinstaller - “ModuleNotFoundError: No module named 'acrcloud_extr_tool'”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM