Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook for pytorch #2666

Closed
AceCoooool opened this issue Jun 25, 2017 · 19 comments
Closed

Hook for pytorch #2666

AceCoooool opened this issue Jun 25, 2017 · 19 comments
Labels
good first issue This is a good issue if you want to start working on PyInstaller pull-request wanted Please submit a pull-request for this, maintainers will not actively work on this.

Comments

@AceCoooool
Copy link

AceCoooool commented Jun 25, 2017

pyinstaller test.py is completed successfully. However, when run this exe file, there is the error like that:

File "/home/ace/.pyenv/versions/anaconda3-4.2.0/lib/python3.5/site-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages/torch/__init__.py", line 302, in <module>
  File "site-packages/torch/__init__.py", line 297, in manager_path
RuntimeError: Unable to find torch_shm_manager at /home/ace/Developer/temp/dist/test/torch/lib/torch_shm_manager
Failed to execute script test

This is maily caused by path,torch_shm_manager is in the file /home/ace/.pyenv/versions/anaconda3-4.2.0/lib/python3.5/site-packages/torch/lib/torch_shm_manager. (this is because pyinstaller change the file to the current file: /home/ace/Developer/temp/dist/test)
How can I just let my torch package not change the file ? (Even I can not use this exe file in other computers)

Could anyone help me? thank you.

@AceCoooool
Copy link
Author

I using a very silly way: add the torch package to the /home/ace/Developer/dist/test . That's work.

@iamtodor
Copy link

iamtodor commented Mar 6, 2018

It takes me a while to figure out the solution from @AceCoooool
Here is the code

cnn2@cnn2:~$ cd ~/.local/lib/python3.6/site-packages

I assume your torch is placed right there

cnn2@cnn2:~/.local/lib/python3.6/site-packages$ cp -a torch/. your/dist/location

It copies all content from torch to your desired location.

Basically, I think it's a bug that should be fixed @htgoebel

@htgoebel
Copy link
Member

htgoebel commented Mar 6, 2018

@iamtodor This way work, but it is not what I'd call a solution. A solution would be to provide a hook, so others will not step into these issue.

@iamtodor
Copy link

iamtodor commented Mar 6, 2018

@htgoebel yes, this way is very dirty. So that's why I ask to call it the bug and fix it

@htgoebel
Copy link
Member

htgoebel commented Mar 6, 2018

@iamtodor You are very welcome to provide a pull-request: https://pyinstaller.readthedocs.io/en/stable/hooks.html

@htgoebel htgoebel added good first issue This is a good issue if you want to start working on PyInstaller pull-request wanted Please submit a pull-request for this, maintainers will not actively work on this. and removed kind:support labels Mar 6, 2018
@htgoebel htgoebel reopened this Mar 6, 2018
@Microactive
Copy link

Have you solve the problem?
Now I meet the similar problem. My test.py only several lines code:
import torch
a = torch.zeros(2, 3)
print(a)

pyinstaller test.py is completed successfully. However, when run this exe file, there is the error like that
Failed to execute script test. I did as @AceCoooool did. But it can't work. there is the error like that
Failed to execute script test.

@Vishwaatpurdue
Copy link

Hi,
I have a similar issue. I used the hook mentioned here to load the torch dependencies, but the exe is not working in other windows machines (I built the exe for windows).

@KnightOfTheMoonlight
Copy link

You may try reinstall pytorch. That works for me.

@MarcinMisiurewicz
Copy link

MarcinMisiurewicz commented Jul 2, 2019

I've run into similar problem, but none of the workarounds work. What is strange, my .exe file works when run from anaconda environment (any env: with or without torch installed), but when I try to run it from cmd outside of anaconda it gives me error:

Traceback (most recent call last):
  File "verify.py", line 1, in <module>
  File "C:\ProgramData\Anaconda3\envs\py367\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\torch\__init__.py", line 79, in <module>
ImportError: DLL load failed: The specified module could not be found.
[11108] Failed to execute script verify

line 1 in verify.py is import torch
Do you have any idea what causes it? Any hints on where to look for it?

Win 10
Anaconda with python 3.6.7 (on 3.7 also fails)
PyInstaller 3.4
PyTorch 1.1.0

@raviv
Copy link

raviv commented Jul 3, 2019

I'm having a similar issue:
Same platform as @MarcinMisiurewicz, but the exe can't find pytorch unless I'm in the conda env used to build it.
Oddly, pyinstaller did copy torch to the dist folder, but the exe still can't find it.

Update
It seems to depend on how pytorch was installed in the conda env from which you run pyinstaller.
If pytorch was installed using conda (e.g. conda install pytorch torchvision cudatoolkit=10.0 -c pytorch) the resulting exe won't work unless the cudatoolkit conda package is installed.
However, if pytorch was installed using pip, the resulting exe works just fine outside of conda env.

@MarcinMisiurewicz
Copy link

MarcinMisiurewicz commented Jul 3, 2019

@raviv Wow, it works! Thank you - it's third day I'm trying to get it work.

I'm wondering what is the source of this problem, is it pytorch for windows, or pyinstaller?

Additional note: when I'm using plain Python (without conda), with pytorch installed from pip, it also crushes, exactly like above. So it seems that the workaround is to use conda, but install pytorch with pip (???). I don't know, it is some dark wizardry here...

@raviv
Copy link

raviv commented Jul 3, 2019

@MarcinMisiurewicz glad it worked for you.
It seems that pyinstaller doesn't pick up the dependency of pytorch from conda, on cudatoolkit10.

@MarcinMisiurewicz
Copy link

when I've checked the dependency walker it think it was both: cudatoolkit and Python37.dll. I'll check it

@raviv
Copy link

raviv commented Jul 4, 2019

@MarcinMisiurewicz After removing pytorch from conda and installing it using pip (in coda env) I can now build an exe that runs on a clean windows machine, with CUDA toolkit and driver installed of course.

@htgoebel htgoebel changed the title Problem with pytorch Hook for pytorch Nov 16, 2019
@parth52
Copy link

parth52 commented Dec 21, 2019

@raviv glad it worked for you.
It seems that pyinstaller doesn't pick up the dependency of pytorch from conda, on cudatoolkit10.

i made a simple application to calculate speed between cpu and gpu and its works fine in my anaconda environment but whenever i am trying to make .exe of that particular file which raise an error that cudatoolkit is not found do conda install cudatoolkit

my code as below temp.py file

from numba import jit,cuda
import numpy as np

to measure exec time

from timeit import default_timer as timer

normal function to run on cpu

def func(a):
for i in range(10000000):
a[i]+= 1

function optimized to run on gpu

@jit(target ="cuda")
def func2(a):
for i in range(10000000):
a[i]+= 1
if name=="main":
n = 10000000
a = np.ones(n, dtype = np.float64)
b = np.ones(n, dtype = np.float32)

start = timer() 
func2(a) 
print("with GPU:", timer()-start) 
   
  
start = timer() 
func(a) 
print("without GPU:", timer()-start)  
ll=input()
print(ll)

and error which i got as below while i am running exe file:-

cudatoolkit is not found

whereas i installed cudatoolkit=9.0 in my conda environment.

and if i try to make .exe using either conda or cmd its give me an same error

@jurneo
Copy link

jurneo commented Jul 19, 2020

You may try reinstall pytorch. That works for me.

this is also a solution for me.

@bwoodsend
Copy link
Member

This was fixed in #3657.

@bmahlbrand
Copy link

This was fixed in #3657.

definitely still a thing in 4.4

@bwoodsend
Copy link
Member

Open a new issue if you want us to be able do anything about it. I imagine that pytorch has changed a bit since 3 and a half years ago.

@pyinstaller pyinstaller locked and limited conversation to collaborators Feb 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue This is a good issue if you want to start working on PyInstaller pull-request wanted Please submit a pull-request for this, maintainers will not actively work on this.
Projects
None yet
Development

No branches or pull requests