I have to use some old code that depends on Python 2.7 but I use Python 3. To change Python versions, I created a virtual environment (specifying Python to be version 2) but my python version didn't seem to change.
Here's what I tried:
conda create -n python_two_env python=2.7
This created the environment, then I activated it using:
conda activate python_two_env
and checked the python version using:
python --version
I got:
Python 3.10.10
Why is the virtual environment's python version not 2.7?
After some troubleshooting, I found that the issue was in my .bashrc
file. Specifically, I had defined the alias python=python3
which was being prioritized over the virtual environment's python version. After commenting out that alias, python --version
in the virtual environment returns Python 2.7.18 :: Anaconda, Inc.