How to use python3 in virtual environment [duplicate]
Andrew Henderson
I want to create virtual environment using python3. But it takes python2 by default. I have both python2 and 3 installed on my machine.
The ouput of when I create the virtual environment is:
$ virtualenv .env
Running virtualenv with interpreter /usr/bin/python2
New python executable in /some/path/.env/bin/python2
Also creating executable in /some/path/.env/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
I would like to specify which python version to use in the virtualenv.
02 Answers
When using virtualenv these are the usual steps to follow:
Create the virtualenv using a specific python version of your liking using the -p or --python arguments
virtualenv -p /usr/bin/your-python ./path-where-to-create-venv
Activate the virtualenv, in order to install libraries et cetera
source ./venv-path/bin/activate
You can see that you're working from inside the virtualenv, you can deactivate using
deactivate
use
virtualenv --python=python3.5 myenv