The Python Oracle

Using Python 3 in virtualenv

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Over Ancient Waters Looping

--

Chapters
00:00 Using Python 3 In Virtualenv
00:44 Accepted Answer Score 1504
01:02 Answer 2 Score 302
01:29 Answer 3 Score 67
02:02 Answer 4 Score 44
02:10 Thank you

--

Full question
https://stackoverflow.com/questions/2384...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #python3x #virtualenv

#avk47



ACCEPTED ANSWER

Score 1504


simply run

virtualenv -p python3 envname

Update after OP's edit:

There was a bug in the OP's version of virtualenv, as described here. The problem was fixed by running:

pip install --upgrade virtualenv



ANSWER 2

Score 302


Python 3 has a built-in support for virtual environments - venv. It might be better to use that instead. Referring to the docs:

Creation of virtual environments is done by executing the pyvenv script:

pyvenv /path/to/new/virtual/environment

Update for Python 3.6 and newer:

As pawciobiel correctly comments, pyvenv is deprecated as of Python 3.6 and the new way is:

python3 -m venv /path/to/new/virtual/environment



ANSWER 3

Score 67


I'v tried pyenv and it's very handy for switching python versions (global, local in folder or in the virtualenv):

brew install pyenv

then install Python version you want:

pyenv install 3.5.0

and simply create virtualenv with path to needed interpreter version:

virtualenv -p /Users/johnny/.pyenv/versions/3.5.0/bin/python3.5 myenv

That's it, check the version:

. ./myenv/bin/activate && python -V

There are also plugin for pyenv pyenv-virtualenv but it didn't work for me somehow.




ANSWER 4

Score 44


virtualenv --python=/usr/bin/python3 <name of env>

worked for me.