There are situations when we need to have multiple versions of python, for instance, when we need to install dependencies that are not compatible with the python version we are running. I have run into a situation where a dependency I need to install is only compatible with previous versions of python. To solve this problem, I had to run the previous version of python in a virtual environment. I use virtualenv utility, which enabled me to run multiple versions of python. I will be explaining some of the steps I followed to get things running.
Install virtualenv
pip install virtualenvDownload the desired version of python
I already had my main python installed in this path: C:\Python\Python311\
I install the previous version of python here: C:\Python\Python310\Create a project directory
I created a project directory here: C:\Python_Workspace\my_project\Create a virtual environment in your project directory
Open the terminal and change directory to project directory
cd C:\Python_Workspace\my_project\
Create your virtual environment
python -m virtualenv -p C:\Python\Python310\python.exe my-virtual-envActivate virtual environment
.\my-virtual-env\Scripts\activateTo deactivate the virtual environment, run
deactivateWe can now go ahead to install all the dependencies we need.
To create a requirements.txt file of all dependencies in the virtual environment, run:
pip freeze > requirements.txt
Top comments (0)