Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pyenv

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
like image 537
Snowcrash Avatar asked Apr 11 '17 12:04

Snowcrash


People also ask

How do I get rid of Pyenv local?

Uninstalling pyenv To disable Pyenv managing your Python versions, simply remove the pyenv init invocations from your shell startup configuration. This will remove Pyenv shims directory from PATH , and future invocations like python will execute the system Python version, as it was before Pyenv.

How do I install a specific version of Python?

Choose the version you wish to install from python.org. Right-click on the link titled Gzipped source tarball of the version you wish to install. From the popout menu choose Copy Link Location. These commands install your local version of python to /home/username/opt/python-3.10.

What does Pyenv local do?

pyenv localSets a local application-specific Python version by writing the version name to a . python-version file in the current directory. This version overrides the global version, and can be overridden itself by setting the PYENV_VERSION environment variable or with the pyenv shell command.

Where does Pyenv store Python versions?

pyenv global The global Python version is set in the /Users/matthewpowers/. pyenv/version file. Let's change the global version to 3.6.


2 Answers

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.

like image 196
r44 Avatar answered Sep 22 '22 00:09

r44


(Assuming you installed pyenv according to the official instructions.)

pyenv recognizes two kinds of Python installations:

  • system -- Python executables from PATH, regardless of their versions
  • numbered versions -- installed with pyenv install under $PYENV_ROOT/versions

pyenv considers the former installations outside its control, so its commands don't take their versions into account when looking for a specific version.


To find out which installation, from pyenv's POV, your python3 refers to, check

  • pyenv versions
    • whether the selected Python 3 version is "system"; or
  • which python3 (and pyenv which python3 if the former points into <pyenv root>/shims/)
    • whether the result points to outside $PYENV_ROOT

If your 3.6.0 installation is indeed outside of pyenv's control, you need to select it with pyenv local system and make sure on your own that your PATH is arranged to point to it.

  • More specifically, that your PATH first points to <pyenv_root>/shims and then to the correct python3
    • You can use which -a python3 to quickly check that
like image 25
ivan_pozdeev Avatar answered Sep 18 '22 00:09

ivan_pozdeev