How to check PyTorch version?
What you will read?
To check the version of PyTorch installed in your environment, you can use one of the following methods. Choose the one that suits your setup best.
Method 1: Using Python Script
- Open your Python interpreter or create a new Python script.
- Run the following commands:
import torch print(torch.__version__)This will output the version of PyTorch currently installed.
Method 2: Using Command Line
You can also check the PyTorch version directly from the command line (Command Prompt, Terminal, or Anaconda Prompt):
- Open your command line interface.
- Type the following command:
python -c "import torch; print(torch.__version__)"This command executes a small Python snippet that imports the PyTorch library and prints its version.
Method 3: Using Jupyter Notebook
If you are using Jupyter Notebook, you can check the PyTorch version in a notebook cell:
import torch
torch.__version__
This will display the version of PyTorch in the output cell.
Method 4: Using Pip
If you installed PyTorch using pip, you can also check the version by running:
pip show torch
This command will display information about the PyTorch package, including its version.
Conclusion
These methods will help you quickly determine the version of PyTorch installed in your environment. Choose the one that best fits your workflow!
