How to make pip command use pyenv pip rather than default system pip?

Viewed 169

If I've used pyenv to change my Python version, I'd like to have the pip command be aware of this.

As is, it isn't.

Below, I've run pyenv activate py-3.8.6. I'm using Python 3.8.6.

(py-3.8.6) macbookpro13@Mys-MacBook-Pro ~ % which pip
/Users/macbookpro13/Library/Python/2.7/bin/pip
(py-3.8.6) macbookpro13@Mys-MacBook-Pro ~ % pyenv which pip
/Users/macbookpro13/.pyenv/versions/py-3.8.6/bin/pip
(py-3.8.6) macbookpro13@Mys-MacBook-Pro ~ %

But the pip command still runs the default system pip, which means anything installed won't be available to pyenv's managed Python.

How to fix?

2 Answers

I experienced also this issue and managed to resolve by adding the following items to my ~/.zshrc

export PATH=~/.pyenv/shims:$PATH
export PYENV_ROOT=$HOME/.pyenv

You can then check and confirm pip is loading from the pyenv shims

type python
python is /home/user/.pyenv/shims/python

type pip
pip is /home/user/.pyenv/shims/pip

I was able to fix this by moving

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

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi


if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-in    it -)"; fi

.. lower in my .zshrc file. Something else was updating the pip path link.

Related