Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting global python version with pyenv is not working as expected

Tags:

python

pyenv

Regarding pyenv: https://github.com/pyenv/pyenv

I have this:

$ pyenv global 2.7
$ python --version
Python 3.6.4

My pyenv version is:

pyenv 1.2.2

does anyone know the right way to set a python version for any particular shell (and child shells)?

like image 819
Alexander Mills Avatar asked Apr 30 '18 21:04

Alexander Mills


People also ask

What does Pyenv Global do?

pyenv global Sets the global version of Python to be used in all shells by writing the version name to the ~/. pyenv/version file. This version can be overridden by an application-specific . python-version file, or by setting the PYENV_VERSION environment variable.

Where are Pyenv Python versions installed?

Once pyenv has determined which version of Python your application has specified, it passes the command along to the corresponding Python installation. Each Python version is installed into its own directory under $(pyenv root)/versions . For example, you might have these versions installed: $(pyenv root)/versions/2.7.


1 Answers

Just to elaborate on my comment, now that I have some time.

The docs describe the shell command for this purpose, which you can run like so:

pyenv shell pypy-2.2.1

Notes:

If you installed pyenv via Homebrew et al, that should work out of the box (it did for me). If not, the installation instructions detail a necessary step:

Add pyenv init to your shell to enable shims and autocompletion. Please make sure eval "$(pyenv init -)" is placed toward the end of the shell configuration file since it manipulates PATH during the initialization.

The specific command they suggest (for bash) is:

$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

Then restart the shell.

There is some further caveats for specific shells listed on the installation instructions linked. Hope this helps.

like image 173
patrick Avatar answered Sep 28 '22 08:09

patrick