The Python Oracle

Using Python 3 in virtualenv

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Track title: CC H Dvoks String Quartet No 12 Ame

--

Chapters
00:00 Question
00:54 Accepted answer (Score 1491)
01:16 Answer 2 (Score 291)
02:03 Answer 3 (Score 63)
02:44 Answer 4 (Score 60)
04:37 Thank you

--

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

Question links:
[virtualenv]: https://virtualenv.pypa.io/en/latest/

Accepted answer links:
[here]: https://github.com/pypa/virtualenv/issue...

Answer 2 links:
[venv]: https://docs.python.org/3/library/venv.h...
[pawciobiel]: https://stackoverflow.com/users/2829223/...
[comments]: https://stackoverflow.com/questions/2384...
[deprecated]: https://docs.python.org/3.6/whatsnew/3.6...

Answer 3 links:
[pyenv]: https://github.com/yyuu/pyenv
[pyenv-virtualenv]: https://github.com/yyuu/pyenv-virtualenv...

--

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.