how to import a torch 1.7.1 when torch 1.4.0 is also installed
how to import a torch 1.7.1 when torch 1.4.0 is also installed
When I run the command: ! pip list
It lists all libraries with : torch    1.7.1
Now when I run:
&gt;&gt;&gt;import torch
&gt;&gt;&gt;torch.__version__
'1.4.0'

How Do I import torch==1.7.1 in the python program?
I am using python 3.8.3 and windows 10

Slightly different way to answer your question, but if you want to have two versions of torch installed simultaneously for different purposes (e.g. running different programs), my recommendation would be to use torch 1.7.1 and torch 1.4.1 in separate virtual environments.  Please see the links below for guides on getting started with these:

virtualenv:

# Create virtual environment
python3 -m venv torch-env

# Activate virtual environment
torch-env\Scripts\activate.bat

# Any packages you install now are ONLY for this virtual environment
pip install torch==1.7.1  # Or 1.4.1 in a separate environment


conda:

# Create virtual environment with Python 3.8.3
conda create --name torch-env python=3.8.3

# Activate virtual environment
conda activate torch-env

# Install torch
pip install torch==1.7.1  # Or 1.4.1

Creating separate virtual environments will allow you to have multiple versions of torch simultaneously without any issues.  You should then be able to import as you do above and use them interchangeably simply by switching environments.
