Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'torch' has no attribute '__version__'

Tags:

python

pytorch

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/):

  • torch==1.7.1+cu110
  • torchaudio==0.7.2
  • torchvision==0.8.2+cu110

Environment:

  • OS: Ubuntu 18.04
  • GPU Geforce RTX 3070
  • Driver version 460.39
  • Cuda Toolkit V11.0.194
  • Cudnn V8.0.5.39
  • Python V3.6.9

Do not understand what's the problem

like image 923
Kracozebr Avatar asked Jun 27 '26 12:06

Kracozebr


2 Answers

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.

like image 161
Andy Chase Avatar answered Jun 30 '26 03:06

Andy Chase


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.

like image 25
Arthur knn Avatar answered Jun 30 '26 01:06

Arthur knn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!