How to install pip for Python 3 on Mac OS X?
UPDATE: This is no longer necessary as of Python3.4. pip3 is installed as part of the general Python3 installation.
I ended up posting this same question on the python mailing list, and got the following answer:
# download and install setuptools
curl -O https://bootstrap.pypa.io/ez_setup.py
python3 ez_setup.py
# download and install pip
curl -O https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
Which solved my question perfectly. After adding the following for my own:
cd /usr/local/bin
ln -s ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/pip pip
So that I could run pip directly, I was able to:
# use pip to install
pip install pyserial
or:
# Don't want it?
pip uninstall pyserial
Cannot install pip in python 3 mac OSX Big Sur
Try the following command:
pip3 install package-name
If you still get the same error message, refer to the following link to get detailed instructions on pip installation on macOS:
https://www.geeksforgeeks.org/how-to-install-pip-in-macos/
How to install pip with Python 3?
edit: Manual installation and use of setuptools
is not the standard process anymore.
If you're running Python 2.7.9+ or Python 3.4+
Congrats, you should already have pip
installed. If you do not, read onward.
If you're running a Unix-like System
You can usually install the package for pip
through your package manager if your version of Python is older than 2.7.9 or 3.4, or if your system did not include it for whatever reason.
Instructions for some of the more common distros follow.
Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 2.x
Run the following command from a terminal:
sudo apt-get install python-pip
Installing on Debian (Wheezy and newer) and Ubuntu (Trusty Tahr and newer) for Python 3.x
Run the following command from a terminal:
sudo apt-get install python3-pip
Note:On a fresh Debian/Ubuntu install, the package may not be found until you do:
sudo apt-get update
Installing pip
on CentOS 7 for Python 2.x
On CentOS 7, you have to install setup tools first, and then use that to install pip
, as there is no direct package for it.
sudo yum install python-setuptools
sudo easy_install pip
Installing pip
on CentOS 7 for Python 3.x
Assuming you installed Python 3.4 from EPEL, you can install Python 3's setup tools and use it to install pip
.
# First command requires you to have enabled EPEL for CentOS7
sudo yum install python34-setuptools
sudo easy_install pip
If your Unix/Linux distro doesn't have it in package repos
Install using the manual way detailed below.
The manual way
If you want to do it the manual way, the now-recommended method is to install using the get-pip.py
script from pip
's installation instructions.
Install pip
To install pip, securely download
get-pip.py
Then run the following (which may require administrator access):
python get-pip.py
If
setuptools
is not already installed,get-pip.py
will install setuptools for you.
How to use pip with python 2 & 3 installed? (OSX)
In all likelihood, pip3
will be installed pointing to your Python 3 installation, so your use case is probably solvable by just switching from:
$ pip install foo
to:
$ pip3 install foo # Or pip3.7 install foo if you need to disambiguate further
That said, it can get kind of complicated when you have many different Python installs, where pip
/pip3
might have been installed pointing to a Python version that doesn't correspond to the python
/python3
you're using, which can be quite confusing.
If you know python
& python3
are the correct executable, just use it to invoke pip
on your behalf. It's fairly easy too, just check your version to be sure it's the one you expect (e.g. on my system):
$ python --version
Python 2.7.15rc1
$ python3 --version
Python 3.6.6
then use the appropriate one with -mpip
, a flag to run an installed module/package via the chosen Python as the "main" executable, bypassing the need for specifically versioned pip
executable entirely. So if you wanted to install foo
for Python 3.6 on my machine, you'd run:
$ python3 -mpip install foo
This is especially useful on Windows, where the pip
executables often either don't exist, or are not installed in the PATH
, so it's irritating to use them. Instead, use the Windows launcher that comes with any modern Python 3 version (but manages all Python versions on the machine), and is used to disambiguate among various versions. For example:
C:\>; Installs foo for latest installed version of Python 3
C:\>py -3 -mpip install foo
C:\>; Installs foo for latest installed version of Python 2
C:\>py -2 -mpip install foo
C:\>; Installs foo for latest installed version of Python 3.6
C:\>py -3.6 -mpip install foo
Essentially, any use of pip
can be replaced by executing the Python interpreter directly with the -mpip
option to run the pip
package as the "main" executable.
This trick applies to many other tools with dedicated launchers that are often not installed in the PATH
, particularly on Windows, and it makes updates easier too; my Windows shortcut for launching ipython3
never used a hardcoded path to the launcher (e.g. C:\Program Files\Python36\Scripts\ipython3.exe
), instead using %WINDIR%\py.exe -3 -mIPython
. In addition to being more portable (the shortcut "just works" on any Windows system with a semi-recent Python 3 install), it's self-updating; when I upgraded from 3.6 to 3.7, the shortcut didn't have to change at all (I had to run py -3 -mpip install ipython
again to get IPython reinstalled, but once I'd done that, the shortcut seamlessly began referring to the 3.7 install with no changes needed).
Python pip installation on Mac is not working
Look at the final warning, which says that these scripts are not in PATH. Open Finder, and copy the listed files into the following directory: /usr/local/bin/
Go to /Users/arnau/Library/Python/2.7/bin. Duplicate the files listed into /usr/local/bin/ so that the command-line can recognize your command, pip.
If you don’t want to do this (which I don’t suggest), you can simply use the other answers for now which say to use python -m pip
, which directs the command-line to the current directory of these files, /Users/arnau/Library/Python/2.7/bin. You may, however run into problems in the future doing this, so I suggested my above answer.
I also expect that you won’t want to type an additional 2 keywords every time you have to install a package.
Related Topics
Extension Method for Python Built-In Types
How to Convert a Python Datetime.Datetime to Excel Serial Date Number
Cancel an Already Executing Task with Celery
Keras Sequential Model Input Layer
Python Argparse - Add Argument to Multiple Subparsers
Code for Greatest Common Divisor in Python
Unique Combinations of Values in Selected Columns in Pandas Data Frame and Count
How to Insert Data into a MySQL Database
Why Doesn't Exec Work in a Function with a Subfunction
Getting the Index of a Row in a Pandas Apply Function
Intersection of Two Lists Including Duplicates
Convert Words Between Verb/Noun/Adjective Forms
Matplotlib Scatterplot with Legend
How to Check If a Column Exists in Pandas
How to Import a Text File on Aws S3 into Pandas Without Writing to Disk
Why Is the Borg Pattern Better Than the Singleton Pattern in Python
Is Close() Necessary When Using Iterator on a Python File Object