8

using pyenv 2.0.3

when i'm in a folder with a python-version file, the python keeps using the system version which is 2.7.6. (not sure why it is 2.7.6 since i install 3.9.7 via brew).

$ python -V
Python 2.7.16

looking via pyenv gives

$ pyenv which python
/Users/jaco/.pyenv/versions/trading/bin/python

Activating it already says it is activated.

i have

# pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

in my zshrc

also don't seem to have the bin folder of pyenv? is this new on the v2?

$ l /Users/jaco/.pyenv/bin
ls: /Users/jaco/.pyenv/bin: No such file or directory

Also setting pyenv global 3.9.1 does not work, it keeps 2.7

Tjorriemorrie
  • 16,818
  • 20
  • 89
  • 131
  • It might be simpler to just use `~/.pyenv/versions/something/bin/python -m venv some_path` to create a virtualenv in `some_path` that uses a Pyenv-installed Python. – AKX Jul 12 '21 at 10:43

4 Answers4

17

The answer is to put the shims on the path

# pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims:$PATH"
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
#if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
Tjorriemorrie
  • 16,818
  • 20
  • 89
  • 131
8

Assuming you're running MacOS and have installed pyenv via Homebrew, you'll need to do the following:

# Adjust the session-wide environment for your account.
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile

# Enable autocompletion and all subcommands
echo 'eval "$(pyenv init -)"' >> ~/.zshrc

From pyenv installation docs:

MacOS note: If you installed Pyenv with Homebrew, you don't need to add the PYENV_ROOT= and PATH= lines. You also don't need to add commands into ~/.profile if your shell doesn't use it.

j4ckofalltrades
  • 572
  • 1
  • 5
  • 16
1

I typed pyenv versions and it showed:

  system
  2.7.18
* 3.10.0 (set by PYENV_VERSION environment variable)
  3.8.13

Then I simply ran unset PYENV_VERSION and when I ran pyenv versions again it correclty selected the local version I intended (2.7.18).

carla
  • 1,970
  • 1
  • 31
  • 44
0

I was on my ~ folder and trying to run pyenv global 3.10.4 BUT python -V was only running 3.8.3 tried everything and was in despair.

The problem was that on my ~ there was a .python-version file pointing to 3.8.3.

Solution: check and remove .python-version

Jorge Mendes
  • 388
  • 3
  • 14