I can't figure out why pyenv
(installed via homebrew) doesn't seem to work.
It seems like my $PATH
variable isn't updated correctly by pyenv and therefore none of the interpreters installed via pyenv can be found. For example, for python version 3.6.8:
$ pyenv versions
system
* 3.4.10 (set by /Users/cglacet/.pyenv/version)
* 3.5.7 (set by /Users/cglacet/.pyenv/version)
* 3.6.8 (set by /Users/cglacet/.pyenv/version)
* 3.7.3 (set by /Users/cglacet/.pyenv/version)
* 3.8-dev (set by /Users/cglacet/.pyenv/version)
$ pyenv which python3.6
/Users/cglacet/.pyenv/versions/3.6.8/bin/python3.6
$ $(pyenv which python3.6) --version
Python 3.6.8
$ pyenv shell
pyenv: no shell-specific version configured
$ pyenv local
pyenv: no local version configured for this directory
Up until here everything looks just fine, but:
$ python3.6 --version
-bash: python3.6: command not found
$ python --version
Python 3.7.0
If I check my PATH
environment variable, I can't see any path of the form /Users/cglacet/.pyenv/versions/3.x.x/bin
.
Note that 3.7.0
is the python version I had before installing pyenv (the system one). What I expect is to have 3.6
available (all versions installed via pyenv), which should be the case as I activated it as a global interpreter as shown before. The expected behavior is:
$ python3.6 --version
Python 3.6.8
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.8/ $(pyenv root)/versions/3.4.2/
To update pyenv and plugins (including pyenv-update itself), just type pyenv update .
More precisely, it installs packages into an existing Python installation, for example in /usr/lib/python3/dist-packages/ . If pip is run inside a pyenv environment, it will install the packages into the currently enabled Python environment, somewhere under $PYENV_ROOT .
After a bit of digging I found that homebrew install failed to edit my .bash_profile
. The problem is that pyenv
itself doesn't rely on these additions and therefore the bug is silent (you just don't have the interpreters in your path).
If you are in this case you'll have to run part of the install manually (starting at "#2 Configure your shell's environment for Pyenv" and add the following in your ~/.bash_profile
(preferably append this new path so it arrives before your system python path, in other word, append this at the end of your bash profile):
export PATH=$(pyenv root)/shims:$PATH
That solves the problem I had (as the directory $(pyenv root)/shims
contains all the interpreters you installed via pyenv
). But you might want to have the complete set of features that pyenv offers (eg., autocompletion of commands), which (in theory) could be done by adding the following to your .bash_profile
instead of the PATH
export:
eval "$(pyenv init -)"
But for me that didn't work as pyenv init
produced some faulty code (missing function
declaration), on the other hand you can use the following and it should work (better):
eval "$(pyenv init - | sed 's:^pyenv() :function pyenv():')"
I still have no idea why the installation failed on my system, if anyone as a clue that would be interesting (and that would probably deserve a fix because I probably won't be the only one having this issue).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With