I installed pytorch using conda command when the virtual env was activated.
But, there are some problems when I import torch modules in Jupyter Notebook.
I checked the sys.path both in the prompt and in Jupyter Notebook.
Well.. in the prompt, the result of sys.path
is
['', '/home/usrname/anaconda3/lib/python36.zip',
'/home/usrname/anaconda3/lib/python3.6',
'/home/usrname/anaconda3/lib/python3.6/lib-dynload',
'/home/usrname/anaconda3/lib/python3.6/site-packages']
and there are no errors when I import torch modules.
But, in the jupyter notebook(executed in chrome), the sys.path
is
['',
'/home/usrname/anaconda3/lib/python36.zip',
'/home/usrname/anaconda3/lib/python3.6',
'/home/usrname/anaconda3/lib/python3.6/lib-dynload',
'/home/usrname/anaconda3/lib/python3.6/site-packages',
'/home/usrname/anaconda3/lib/python3.6/site-packages/IPython/extensions',
'/home/usrname/.ipython']
and I see an error: No module named 'torch'
I can't solve this problem...
This is most probably because you are using a CUDA variant of PyTorch on a system that doesn't have GPU driver installed. That is to say, if you don't have a Nvidia GPU card, please install the cpu-only package according to the commands on https://pytorch.org.
Anaconda is the recommended package manager as it will provide you all of the PyTorch dependencies in one, sandboxed install, including Python.
First of all Just Create conda environment. conda create -n env_pytorch python=3.6 And then Activate Environment. conda activate env_pytorch Now Just install PyTorch using pip This command. This will install both torch and torchvision.
I had the same issues with this but managed to solve the problem. I think PyTorch has an 'issue' with the regular Jupyter application in Anaconda, so I urge you to first install the numpy jupyter notebook that supports PyTorch, then you can launch you notebook again. Use (while in your virtual env path):
conda install numpy jupyter notebook
Hope this helps.
This works for me:
1.Create a conda virtual environment:
conda create -n env_pytorch python=3.6
2.Active this environment create above:
source activate env_pytorch
3.Install PyTorch with pip or pip3:
pip install torchvision --user
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With