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
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 .
Step 1: Download the get-pip.py (https://bootstrap.pypa.io/get-pip.py) file and store it in the same directory as python is installed. Step 2: Change the current path of the directory in the command line to the path of the directory where the above file exists. Step 4: Now wait through the installation process. Voila!
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.
I am sharing my realtime experience,
my system is pointing default to python2.7 even though I installed python3.6 in my machine
But when I trying to download new packages for python3.6,But it is downloading with default python2.7
so I came across this pyenv,
I installed the pyenv
after installing
$ pyenv install --list
$ pyenv global
pointing to default system(python2.7)
installed python3.6
$ pyenv install 3.6.9
changed from python2.7 to python3.6
$ pyenv global 3.6.9
Here, we have to notice that by installing pyenv by default pip is installed.
using pip command I installed required package which for python3.6 without adding suffix number like pip3.
$ pip install pyOpenSSL
suppose if you want installed the package related python2.7 then change then python environment
$ pyenv global 2.7.0
and you can install your required package using pip instead of using pip3
pip install package-name
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