hkitano
hkitano

Reputation: 129

Pytorch module not found

I'm using Python 3.6, and trying to use Pytorch. I've uninstalled it using pip3, and re-installed it

Hugos-MacBook-Pro-2:project hugokitano$ pip3 install torch 
Requirement already satisfied: torch in /usr/local/lib/python3.7/site-packages (1.3.1) 
Requirement already satisfied: numpy in /Users/hugokitano/Library/Python/3.7/lib/python/site-packages (from torch) (1.17.2)

However, when I try to import torch, the module is not found. I've also tried to install via conda, running

conda install pytorch torchvision -c pytorch

and it was successful, installing to

environment location: /Users/hugokitano/anaconda

However, "import torch" still doesn't work. Any thoughts? Thanks!

Upvotes: 0

Views: 7648

Answers (2)

Prayson W. Daniel
Prayson W. Daniel

Reputation: 15558

It is wise to use environments instead of installs packages on your base. Try do the following:

conda create -n deep7 -c pytorch python=3.7 pytorch torchvision
conda activate deep7
python -c "import torch"

We have created an environment with name deep7, we use pytorch channel to install pytorch in Python 3.7. After that we activate the environment and test if the import works. If it did you will see no error.

To use pytorch, you will have to activate your environment: conda activate deep7 and to deactivate conda deactivate. You can add libraries with conda install -n deep7 <package name>

Happy coding

BTW: if you want Python 3.6, do the same, change all the 7 above to 6 :)

Upvotes: 2

user11751534
user11751534

Reputation:

Try to update conda and install it. It weirdly fixed my issue.

conda update conda

Upvotes: 0

Related Questions