pyenv local - can't set a Python version by its number despite the fact that it's installed

Snowcrash picture Snowcrash · Apr 11, 2017 · Viewed 9.1k times · Source

Any suggestions on how you set the version of Python for pyenv?

E.g.

$ python3
Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13) 
$ pyenv local
pyenv: no local version configured for this directory
$ pyenv local 3.6.0
pyenv: version `3.6.0' not installed
$ pyenv local v3.6.0:41df79263a11
pyenv: version `v3.6.0' not installed

Answer

r44 picture r44 · Jun 19, 2017

You need to set up an virtual env first. For example, you can create a env called pyenv360 by

$ pyenv virtualenv 3.6.0 pyenv360

And set it as your default python for your folder my-folder by

$ cd my-folder
$ pyenv local pyenv360

By doing this, whenever you enter this folder, it'll start using pyenv360 which references python 3.6.0 in this case.

You can check if it's working by:

$ pyenv local

which should show pyenv360.