I’ve double checked to ensure that the conda environment is activated. I redownloaded PyTorch using conda install -c pytorch pytorch. When I do conda list I can see pytorch 1.0.1 py3.6_cuda10.0.130_cudnn7.4.2_2 pytorch listed.
Not too sure what else I can try to figure out why I’m getting this error. Any help would be appreciated!
conda list | grep torch shows the PyTorch installation in your custom environment?
If you start a REPL session using python in your terminal, can you import torch then?
Are there other PyTorch-related files in your working directory, e.g. the source code from another installation?
Based on another suggestion on this forum, I also tried going into the directory on my $PYTHONPATH and doing ls | grep torch, which didn’t return anything. I’m not sure if this would be related?
and then try to reinstall it?
I’m not sure what might go wrong, if you just open a REPL session and try to import torch after installing it.
Also, make sure your working directory (from which you call python in the terminal) is not in any PyTorch source folder.
I did all that you advised. uninstalled torch completely and installed with either the conda or pip but no luck with either of them.
Although the problem in my case is importing torch in a jupyter notebook. No error while running any script from the terminal but error shows up in importing torch in a jupyter notebook. I also made new environment but still the error persists. Tried on different python versions as well. Please help!
Using Ubuntu and Anaconda.
When conda list | grep torch gave
Most likely your Jupyter notebook is using a different Python kernel than the one used in the terminal.
You should be able to select the right Python kernel in the notebook directly.
Thankfully one of the conda env was running fine all this time but all others were “glitched” (atleast what I thought) somehow.
I just tried importing torch in all the “gliched” env and both the pip and conda installations are working now. I don’t even know what fixed it because I didn’t change anything from the last failed attempt. I just checked version from python shell in command line using platform package and checked the same in jupyter notebook as per your advice. Thank you.