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.