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

ImportError: No module named 'torch' #12004

Closed
edtky opened this issue Sep 24, 2018 · 11 comments
Closed

ImportError: No module named 'torch' #12004

edtky opened this issue Sep 24, 2018 · 11 comments

Comments

@edtky
Copy link

edtky commented Sep 24, 2018

Issue description

I ran the following to installed Pytorch on my windows 10.
conda install pytorch-cpu -c pytorch

But when I tried to import torch, I get the following error:
ImportError: No module named 'torch'

i did a "conda list" and verified that pytorch was install:
pytorch-cpu 0.4.1 py36_cpuhe774522_1 pytorch

Does anyone know how to resolve this?

@peterjc123
Copy link
Collaborator

@edtky Could you please give me the output of the following commands in CMD?

where conda.exe
where pip.exe
where python.exe

@peterjc123
Copy link
Collaborator

@edtky And actually you can try this script: https://gist.github.com/peterjc123/21143c0c9426a025618260dde5b6219a.

@edtky
Copy link
Author

edtky commented Sep 28, 2018 via email

@peterjc123
Copy link
Collaborator

@edtky Looks like you have two Python environments. Please try importing torch in Anaconda Prompt.

@edtky
Copy link
Author

edtky commented Sep 28, 2018 via email

@edtky
Copy link
Author

edtky commented Sep 28, 2018 via email

@peterjc123
Copy link
Collaborator

@edtky Congratulations. Could you please close this issue?

@edtky edtky closed this as completed Sep 28, 2018
@plouismarie
Copy link

plouismarie commented Sep 30, 2018

Also if it works for you in the terminal, using the peterjc123's check script,
but not in jupyter notebook [ you still have the error message : no module named torch ],
then get sure jupyter is properly installed IN YOUR CONDA env too.
If you do not see jupyter in the output of that command line => conda list
then type :
conda install jupyter

@RobbyHuang
Copy link

I used "conda install " command to install pytorch 1.1.0. And I successfully run python3 import torch.
Also I successfully run import torch in jupyter notebook and ipython. But when I run a .py file through a sh file, it failed with the error "ImportError: No module named 'torch'".
How can I handle it. Thank you so much!

$ sudo sh ./experiments/scripts/train_linemod.sh

  • set -e
  • export PYTHONUNBUFFERED=True
  • export CUDA_VISIBLE_DEVICES=0
  • python3 ./tools/train.py --dataset linemod --dataset_root ./datasets/linemod/Linemod_preprocessed
    Traceback (most recent call last):
    File "./tools/train.py", line 13, in
    import torch
    ImportError: No module named 'torch'

@peterjc123
Copy link
Collaborator

@RobbyHuang
Copy link

RobbyHuang commented May 21, 2019

@peterjc123 Thank you for your reply. I have handled this problem. I successfully run a .py file through a sh file using the command sh ./experiments/scripts/train_linemod.sh but not sudo sh ./experiments/scripts/train_linemod.sh

In addition, I have tried to add either /usr/bin/python or /usr/bin/env, but I still failed to run a .py file through a sh file using the command $ sudo sh ./experiments/scripts/train_linemod.sh with the error "ImportError: No module named 'torch'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants