Hi. I have been installing pytorch multiple times. I took into consideration the python environment I was using. After all these, the code that I run still says ModuleNotFoundError: No module named ‘torch’. Could anyone help me in these. I copy the error message below. (I was trying to use stanza to evaluate a model, sorry just a beginner)
(my-torch) Toufig-Lu:stanza yiminglu$ python3 -m stanza.utils.datasets.prepare_mwt_treebank UD_English-TEST
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 187, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 110, in _get_module_details
__import__(pkg_name)
File "/Users/yiminglu/Desktop/stanza-train-master/stanza-train/stanza/stanza/__init__.py", line 1, in <module>
from stanza.pipeline.core import DownloadMethod, Pipeline
File "/Users/yiminglu/Desktop/stanza-train-master/stanza-train/stanza/stanza/pipeline/core.py", line 9, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
I did these multiple times. I created another environment in anaconda, and I did it directly in anaconda, I used pip. At the end, the response is all the same.
Ok, so let’s use the conda environment for the meanwhile. Are you using an integrated developer environment (IDE) like PyCharm, VScode, etc? If so, you’ll need to select the environment within the IDE as well (instead of just the terminal) and select the correct python interpreter, because it’ll default to your base environment that doesn’t have pytorch installed.
You can check what environment you’re using (in conda) via using conda env list within the terminal, you’ll see a * next to the environment you’re using. Could you check that?
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 187, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 110, in _get_module_details
__import__(pkg_name)
File "/Users/yiminglu/Desktop/stanza-train-master/stanza-train/stanza/stanza/__init__.py", line 1, in <module>
from stanza.pipeline.core import DownloadMethod, Pipeline
File "/Users/yiminglu/Desktop/stanza-train-master/stanza-train/stanza/stanza/pipeline/core.py", line 9, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
Hi I solved the problem following this: Install Pytorch with virtualenv · GitHub.
basically install a virtual environment and install pytorch there. I hope it will work for you. But still, I don`t know what goes wrong with the normal environment. It worked fine and one day it no longer worked.
Thank you very much,
What about to create conda env. and I still have the same problem.
conda create --name lab python=3.8 -y
conda activate lab
I even install the torch like:
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
and after that when I mim install mmcv-full it shows me the error of:
Hi I don`t know too much. I am new to this, so I might not be answering your question. I did:
$ python3 -m pip install --user virtualenv #Install virtualenv if not installed in your system
$ python3 -m virtualenv env #Create virtualenv for your project
$ source env/bin/activate #Activate virtualenv for linux/MacOS
$ env\Scripts\activate
And then I pip installed pytorch.
pip3 install torch torchvision torchaudio
Things work after that. I use anaconda and it works fine. No more No module named 'torch'