Python Language Creating a virtual environment for a different version of python


Assuming python and python3 are both installed, it is possible to create a virtual environment for Python 3 even if python3 is not the default Python:

virtualenv -p python3 foo


virtualenv --python=python3 foo   


python3 -m venv foo


pyvenv foo

Actually you can create virtual environment based on any version of working python of your system. You can check different working python under your /usr/bin/ or /usr/local/bin/ (In Linux) OR in /Library/Frameworks/Python.framework/Versions/X.X/bin/ (OSX), then figure out the name and use that in the --python or -p flag while creating virtual environment.