pyenv: pip: command not found
Asked Answered
U

5

40

I'm trying to get Python 2.7 to play nicely with pyenv and virtualenv on OSX El Capitan. I've installed pyenv with Homebrew, then Python 2.7.11 with pyenv install 2.7.11. This describes the setup:

$ which python
/usr/local/bin/python
$ which virtualenv
/usr/local/bin/virtualenv
$ head -1 /usr/local/bin/virtualenv
#!/usr/local/bin/python
$ which pip
/Users/username/bin/pip
$ head -1 /Users/robinedwards/bin/pip
#!/usr/local/bin/python
$ pyenv install --list | grep 2.7.11
  2.7.11

.bashrc contains lines:

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

Now when I try to create a new virtualenv project:

$ pyenv virtualenv 2.7.11 newproject
pyenv: pip: command not found

Any idea what I'm doing wrong?

Urethritis answered 22/4, 2016 at 21:50 Comment(5)
have you execute source command for your .bashrc?Aqua
It executes when I open bash - last line echo .bashrc loaded reports ok..Urethritis
here's a related problem github.com/yyuu/pyenv-virtualenv/issues/71 may help youAqua
@haifzhan But pip is already installed in the normal environment and just seems unavailable to pyenv..Urethritis
Do a type -a pyenv. It should report that pyenv is a shell function. If not, then your evaluation of pyenv init somehow didn’t happen, and you need to take a closer look at your shell startup sequence.Hippocras
D
38

I'm not sure if that solution matches the problem, but after installing pyenv, pyenv-virtualenv and selecting a python version, I had to run pip that way:

$ pyenv exec pip install
Destinydestitute answered 15/6, 2021 at 11:44 Comment(3)
I'm just curious. Any idea why we need to do this? It worked for me but I don't understand whyNata
@A.A I'm guessing that pip is attached to a specific environnement, instead of being globally accessible. But not sure.Destinydestitute
Thank you so much, this solved my issue. It actually worked for running any command for example jupyter notebook after installing itDyne
A
17

I had the same error message. The problem was due to a failed installation of a python version, so pip wasn't found for this version. In fact, even python wasn't found.

example:

pyenv install 3.7.2 # this failed, but I did not realize it failed at first
pyenv versions | grep 3.7.2

3.7.2

pyenv local 3.7.2
python --version

pyenv: python: command not found

So problem was not with pip itself, but a broken installation of a python version. Just make sure you succeed when you install a python version with pyenv.

Attendance answered 28/2, 2019 at 18:53 Comment(0)
I
16

After installing a python version with pyenv with

pyenv install 3.7.13

I first had to run:

pyenv global 3.7.13  

and now pip is working fine.

Izolaiztaccihuatl answered 1/4, 2022 at 19:40 Comment(0)
N
7

You need to install pip separately if you didn't install pyenv from the binaries provided by python.org

After installing the wanted python version, download and install pip :

wget https://bootstrap.pypa.io/get-pip.py
(sudo) python ./get-pip.py​
rm get-pip.py

Ref: https://pip.pypa.io/en/stable/installing/

Norvol answered 6/9, 2016 at 17:28 Comment(0)
C
1

I had a bad configuration using zsh and pyenv. I solved it by removing what I had in ~/.zshrc on pyenv, removing the environment and python version (pyenv uninstall 3.9.0 in my case) and then running the following:

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zprofile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zprofile
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
echo 'eval "$(pyenv init --path)"' >> ~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc

This comes directly from the provided ~/.pyenv/README so I guess it should have been obvious. After reinstalling the python version (pyenv install 3.9.0) and creating the environment again (pyenv virtualenv 3.9.0 my-env) pip worked as expected when activating the environment via pyenv activate my-env

Cartilage answered 23/3, 2022 at 12:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.