Search code examples
pythonvisual-studio-codepyinstallerexetorch

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


[Environment]

  • vscode
  • Anaconda
  • Window

I successfully ran main_for_exe.py in vscode.

When I make exe file using pyinstaller and then ran exe file, however, I have the below error message.

enter image description here

There were some solutions: "add module to 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. So, I think that modules installed by 'pip' and 'conda' aren't loaded.

How do I solve this?


Solution

  • I solved this problem!

    I just upgraded the pyinstaller package.

    It seems that the pyinstaller package, before upgrade, cannot find the site-package path where the modules installed by anaconda are located. (Generally site-packe path: "~/anaconda3/lib/site-packages")

    In this case, there are two solutions.

    1. First, you just upgrade pyinstaller.
    2. Second, you add site-package path to hookspath and then run "pyinstaller main.spec".