How to know torch version that installed locally in your device

Viewed 14745

I want to check torch version in my device using Jupyter Notebook.

I'm used this

import torch
print(torch.__version__)

but it didn't work and Jupyter notebook raised an error as below

AttributeError                            Traceback (most recent call last)
<ipython-input-8-beb55f24d5ec> in <module>
      1 import torch
----> 2 print(torch.__version__)

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

Is there any command to check torch version using Jupyter notebook?

4 Answers

Try this. Open your terminal

python3 -c "import torch; print(torch.__version__)"

enter image description here

enter image description here

I have tried to install new Pytorch version. But, it didn't work and then I deleted the Pytorch files manually suggested on my command line. Finally, I installed new Pytorch version using conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch and everything works fine.

This code works well after that.

import torch
print(torch.__version__)

You can check list all installed python modules with version tag via pip.

To ensure running the proper pip version, just execute it via the python interpreter:

# python symlink
python -m pip freeze
# python3
python3 -m pip freeze

You can grep for the module of question (used numpy as an example)

python -m pip freeze | grep numpy
numpy==1.19.4

If in the terminal, use pip.

user@debian:~/..$ pip3 show torch
Name: torch
Version: 1.11.0
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages@pytorch.org
License: BSD-3
Location: /home/user/.local/lib/python3.7/site-packages
Requires: typing-extensions
Required-by: torchaudio, torchvision
Related