I'm trying to prevent this warning every time I create a fresh .venv:
> /Users/pi/.pyenv/versions/3.10.0/bin/python -m venv .venv
> . .venv/bin/activate
> pip install ipykernel # or anything
WARNING: You are using pip version 21.2.3; however, version 22.2.2 is available.
You should consider upgrading via the '/Users/pi/code/foo/.venv/bin/python -m pip install --upgrade pip' command.
Somehow pyenv has populated my fresh .venv with an out-of-date pip.
If I execute the suggested command it will upgrade my .venv's pip. But I don't want to be doing that every time I create a .venv.
I figured this might fix it, but it doesn't:
> /Users/pi/.pyenv/versions/3.10.0/bin/python -m pip install --upgrade pip
Requirement already satisfied: pip in /Users/pi/.pyenv/versions/3.10.0/lib/python3.10/site-packages (22.2.1)
Collecting pip
Using cached pip-22.2.2-py3-none-any.whl (2.0 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 22.2.1
Uninstalling pip-22.2.1:
Successfully uninstalled pip-22.2.1
Successfully installed pip-22.2.2
What is actually happening when I execute the above command? I was expecting it to update the pip for the python version created/maintained by pyenv. Which it seems to be doing:
🧢 pi#pPro18-4 ~/.pyenv/versions/3.10.0
> find . -name 'pip*'
./bin/pip3
./bin/pip
./bin/pip3.10
./lib/python3.10/site-packages/pip
./lib/python3.10/site-packages/pip-22.2.2.dist-info
🧢 pi#pPro18-4 ~/.pyenv/versions/3.10.0
> ./bin/pip --version
pip 22.2.2 from /Users/pi/.pyenv/versions/3.10.0/lib/python3.10/site-packages/pip (python 3.10)
So why isn't this pip getting copied into my .venv when I create it?
I thought that was the way .venv creation worked.
How to clean up my pyenv Python installation so that it spawns up-to-date .venvs?
EDIT:
Insight from #python on IRC/Libera:
grym: I don't think you can; i just get in the habit of python -m venv somevenv && somevenv/bin/python -m pip install --upgrade pip setuptools wheel
jinsun: python -m venv --upgrade-deps .venv is a simple solution if you were just annoying by the pip warning (...) it is updating the pip inside the venv, forget about the base python, I don't even have pip in the base python
This is the use case for pyenv-hooks
pyenv-hooks are scripts that are executed by pyenv whenever certain commands are run. You can create hooks for regular commands like: exec, rehash, which, but it can also be a plugin command, like virtualenv. The scripts can be written in any language.
Here is the wiki with official instructions.
You can have a hook by creating a script at the following location:
$PYENV_ROOT/pyenv.d/<hook-name>/<your-script-name>
For example, to create a hook that upgrades pip, create a new script within this path:
$PYENV_ROOT/pyenv.d/virtualenv/after.bash
With contents:
after_virtualenv 'PYENV_VERSION="$VIRTUALENV_NAME" pyenv-exec pip install --upgrade pip'
after_virtualenv is the command that tells pyenv when to execute. First, it sets the pyenv version to the name of the virtualenv we just created. with the variable $VIRTUALENV_NAME. Then it upgrades pip itself.
More details in this article.
I originally posted it as a comment, but was suggested to make it a proper answer.
An easier approach is to use the upgrade-deps flag when you create a virtual environment. Like this:
python3 -m venv --upgrade-deps .venv
It was added on python3.9, and according to the official docs:
--upgrade-deps
Upgrade core dependencies (pip, setuptools) to the latest version in PyPI
So, in other words, it will install pip and upgrade right away.
MacBook Pro already had one python 3.8.2 installation. Then I installed anaconda which has python 3.8.5 and installed python 3.9.4 from python.org.
Pip3 is installing packages to anaconda, not for 3.9.4. How to install packages for python 3.9.4 using pip3 from the terminal? Also, how to run python 3.8.2, 3.8.5, 3.9.4 separately from the terminal (along with their respective idle)?
I am not familiar with changing paths, so detailed commands will be very helpful.
(base) ~ % where python3
/Users/user/opt/anaconda3/bin/python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
/usr/local/bin/python3
/usr/bin/python3
(base) ~ % where pip3
/Users/user/opt/anaconda3/bin/pip3
/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3
/usr/local/bin/pip3
/usr/bin/pip3
(base) ~ % where python
/Users/user/opt/anaconda3/bin/python
/usr/bin/python
(base) ~ % where pip
/Users/user/opt/anaconda3/bin/pip
Don't use pip3. Use pip3.8 or pip3.9 or start pip with an explicit python.
pythonx-m pip install package
where pythonx is python3.9 or python3.8. I suspect that python3.8 still starts 3.8.2, but to be sure, just enter python3.8 on the command line and look at startup line. I don't know anything about starting Anaconda python.
Similarly, python3.x -m idlelib` will start IDLE with whatever python3.x starts.
I initially installed Elastic Beanstalk (via $ pip install awsebcli) using Python 2. I want to make sure my application will be deployed with Python 3. I tried uninstalling Elastic Beanstalk ($ pip uninstall awsebcli) and reinstalling it, but when I run $ eb -- version I still get EB CLI 3.12.1 (Python 2.7.1).
I know this question is a few months old but I thought I'd add a clarified answer since I just encountered this.
The Problem
I was trying to install the awsebcli with the python2 version of pip.
If you run pip --version it'll tell you:
$ pip --version
pip 18.0 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
The Solution
What you need it to install pip from python3-pip and use the pip3 command.
First of course if you've installed the awsebcli with this pip version you'll want to remove it.
$ pip uninstall awsebcli
Now install the new python3 version of pip:
$ sudo apt-get install python3-pip
This will make the pip3 command available which manages python3 libraries.
$ pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
Next install the awsebcli with pip3
$ pip3 install awsebcli
Finally check that you've got the right eb version:
$ eb --version
EB CLI 3.14.4 (Python 3.6.5)
I uninstalled pip, and I installed pip3 instead. Now, I want to use pip3 by typing pip only. The reason is I am used to type pip only and every guide uses the pip command, so every time I want to copy and paste commands, I have to modify pip to pip3 which wastes time. When I type pip I have an error which is pip: command not found which means pip command is not taken. Is it possible to make pip points to pip3?
You can use pip3 using the alias pip by adding alias to your .bashrc file.
alias pip=pip3
or by adding a symlink named pip to your $PATH, which points to the pip3 binary.
If there is no ~/.bashrc in your home directory on macOS, inputting
alias pip=pip3
in your ~/.zprofile file has the same effect.
Rather than manually creating your own alias in bash and hoping this doesn't conflict with anything, most package managers should allow you to register the version you wish to use whilst maintaining dependencies.
For instance on Linux:
sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
Or on Mac (MacPorts):
port select --set pip pip3
Solution 1
Check which version pip is pointing to
pip --version
pip 18.0 from /usr/lib/python2.7/site-packages/pip (python 2.7)
If your pip is pointing to pip2, locate where is the pip "binary".
which pip
/usr/bin/pip
This is a simple python script:
cat /usr/bin/pip
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
So just change the shebang from #!/usr/bin/python2 to #!/usr/bin/python3.
Now pip is pointing to pip3.
pip --version
pip 18.0 from /usr/lib/python3.6/site-packages/pip (python 3.6)
Solution 2
Remove /usr/bin/pip make make a symbolic link from the wanted pip version to it instead.
sudo rm /usr/bin/pip
sudo ln -s /usr/bin/pip3.6 /usr/bin/pip
Since you uninstalled pip, this solution assumes you're only going to use pip3.
Open your terminal.
Create a simple link. To do that type:
sudo ln -s /usr/bin/pip3 /usr/bin/pip
Now when you type pip, it will invoke pip3.
Check that it worked by typing pip --version
pip --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
You're all set!
You can install pip after install pip3 by the below command:
pip3 install --upgrade pip
after that:
~ pip --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
You can write pip for pip3 after changing bashrc file in the home directory.
In mac -
Open bashrc file -
vim ~/.bashrc
Add this line at the end of the file -
alias pip="pip3"
Close the file. Don't forget to source this file in the terminal by
source ~/.bashrc
You are good to go. Now, whenever you will use pip in any command. it will be interpreted as pip3
You can check it by running the command -
pip --version
Pip is installed in /usr/bin/. If you don't have pip at all, I would suggest to install pip3 only. Make sure you don't need older version.
You can check available pip versions using following command.
ls /usr/bin/pip*
If you have multiple pip you need to prioritize your pip versions. I had only pip3 so I add it to the first priority. You can use following command and it is done.
sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
You will get output as :
update-alternatives: using /usr/bin/pip3 to provide /usr/bin/pip (pip) in auto mode
Test now:
pip --version
You will get:
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)
If you have other version for python2.7, you can use same update command and change last digit 1 to 2. This will make it second priority.
I believe one shouldn't do such a thing. Actually I would argue it's even better to not use the pip, pip3, etc. scripts ever. Instead one should always prefer the more explicit and surefire way of using pip's executable module for one specific Python interpreter:
path/to/pythonX.Y -m pip somecommand
References:
https://snarky.ca/why-you-should-use-python-m-pip/
https://snarky.ca/a-quick-and-dirty-guide-on-how-to-install-packages-for-python/
This can be done by simply creating an alias for the command.
To create an alias just type
$alias new_command="existing_command"
In your case,
$alias pip="pip3"
Although this isn't permanent. OT make it permanent edit your bashrc file
$ vim ~/.bashrc
an to the end of it append the line.
$alias pip="pip3"
It depends on how you manage your python versions (system, brew, pyenv, ...) and which python installation you are currently using.
For example if you use brew then creating a simlink is a good option:
ln -s -f /usr/local/bin/pip3 /usr/local/bin/pip
validate that pip uses the correct version:
which pip
will give you
/usr/local/bin/pip
Copy the pip3 file and rename as pip:
sudo cp /usr/bin/pip3 /usr/bin/pip
pip --version
and
pip3 --version
Works now.
I've read the Pip related responses and still have this question. I'm trying to install pip on Mac OS X 10.6.8. In brief, I run sudo python get-pip.py and get an error that the pip Requirement is already up to date.
But I don't see a 'pip' executable file in the expected directory and can't run pip. Should there be a file called pip in the target pip folder?
More detail:
I'm following directions at: http://docs.python-guide.org/en/latest/starting/install/osx/
1) Used ez_install to install setuptools
2) bashed:
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py $
sudo python get-pip.py
Response is
Requirement already up-to-date: pip in /Library/Python/2.6/site-packages
... I can see a lot of files in this directory
3) I then try to use pip:
/Library/Python/2.6/site-packages/pip install virtualenv
Get back > pip: is a directory
4) I try
/ Library/Python/2.6/site-packages/pip/pip install virtualenv
-bash: /Library/Python/2.6/site-packages/pip/pip: No such file or directory
I look in the above path and can see the pip folder, with numerous files including __main__ and __init__ but no file named pip. Should there be one? if so, how might I clear out the old install and reinstall?
Thanks for any advice!
SL
Here's how I successfully installed pip from the Github repositories on Max OS X 10.9:
Get pip repository:
$ git clone https://github.com/pypa/pip
Perform setup:
$ cd pip
$ sudo python setup.py install
That's it. A test run should give something like:
$ pip -V
pip 1.6.dev1 from /Library/Python/2.7/site-packages/pip-1.6.dev1-py2.7.egg (python 2.7)
And my PATH environment variable is set to:
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
echo export PATH="/usr/local/bin:$PATH" >> ~/.bash_profile