Reputation: 401
I try to check if torch have been properly installed by script:
import torch
print(torch.__version__)
and have the result: AttributeError: module 'torch' has no attribute 'version'
I've checked if torch is installed in my venv by:
pip freeze
and it is installed(I tried to install as via conda as via pip as suggested at https://pytorch.org/):
Environment:
Do not understand what's the problem
Upvotes: 8
Views: 35879
Reputation: 1368
I was getting this error in Python jupyter notebooks, trying to run code after just installing packages and Microsoft compilation build tools. I found just restarting the "Python kernel" (python instance running in the background) fixed the problem.
Upvotes: 3
Reputation: 16218
Comment by @jodag:
Don't name your file torch.py this will cause your local script to shadow the module named torch. Instead of importing the pytorch module you are importing your local torch.py (/home/evgeniy/cnn/torch.py).
Upvotes: 0
Reputation: 341
I got the same issue, it was related to a a poorly installed version of torch.
Just pip uninstall torch
and pip install torch==2.0.0+cu117
worked for me.
It should also work for another torch version.
Upvotes: 2
Reputation: 74
Pytorch has a sub-module called version and from that you can say,
torch.version.__version__
Upvotes: 1