How to use pip for pyenv?

36,765

When using pyenv, you should be able to set your 'local' version in the directory you are working in, and then pip will rely on this version.

So in your case:

pyenv local 2.7.14
pip install package-name

See more on pyenv commands here: https://github.com/pyenv/pyenv/blob/master/COMMANDS.md

But I do think the main piece that is missing here is a 'virtual environment' to keep your Python packages independent per project (even if they share the same Python version). It is not necessary based on what you are asking, but it is a generally agreed upon best practice. See the Python docs here for more info.

Share:
36,765
HAO CHEN
Author by

HAO CHEN

Updated on December 11, 2020

Comments

  • HAO CHEN
    HAO CHEN over 3 years

    I have installed pyenv in my Mac to manage different python versions.

    Before, I have the system default python 2.7 which is located in /Library/Frameworks/Python.framework/Versions/2.7/ and I also have python3 which is located in /usr/local/bin/python3

    Now, I installed the pyenv and python 2.7.14 which is located in /Users/hao/.pyenv/shims/python2

    I just curious when I want to install some library using 'pip' command, how to make sure I install the library into the right python? For example, I want to use 'pip' to install the torch or tensorflow into pyenv python 2.7.14. But don't want to install them into system default python. Also, how to change the pip3 version?

    Here I using the which pip and which pip3, the results are:

    haos-mbp:~ hao$ which pip
    /Users/hao/.pyenv/shims/pip
    haos-mbp:~ hao$ which pip3
    /usr/local/bin/pip3