Python 3 - Install

Updated: 2018-12-09

Install Python

Mac OS X

Python is shipped with Mac OS X by default: /usr/bin/python

Starting from El Capitan, due to System Integrity Protection(SIP), if pip install fails("operation not permitted"), you can use homebrew to install a local copy:

# Before brew install
$ which python
/usr/bin/python

$ brew install python

# After brew install
$ which python
/usr/local/bin/python

Since Python 3.4, pip is installed alone with Python by default.

Install From Source Code

$ sudo apt-get install libssl-dev openssl
$ wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz
$ tar xzvf Python-3.5.0.tgz cd Python-3.5.0.tgz
$ ./configure
$ make
$ sudo make install

Install Python Without Sudo (Root Privilege)

Specify install path during configure and do not use sudo in make install:

$ ./configure —prefix=$HOME/myfolder
$ make
$ make install

Install pip

This invocation will install pip if it is not already installed, but otherwise does nothing

$ python3 -m ensurepip

to upgrade

$ python3 -m ensurepip --upgrade

or

$ pip install --upgrade pip

Check Version

$ pip -V
pip 8.x.x from /usr/local/lib/python2.7/site-packages (python 2.7)

$ pip3.5 -V
pip 8.x.x from /usr/local/lib/python3.5/site-packages (python 3.5)
  • pip replaces easy_install
  • new packages are delivered as whl instead of egg

    • same: both are zip files
    • differences: egg can be loaded directly without unpacking; wheels have to be unpacked upon installation
  • prefer venv to virtualenv

Check Version

$ pip -V
pip 8.0.2 from /usr/local/lib/python3.5/site-packages (python 3.5)

Upgrade pip

$ pip install -U pip

Using pip

Install packages

$ pip install <package>

Uninstall packages

$ pip uninstall <package>

List installed packages

 $ pip list

Packages are installed in:

  • Mac OS X:

    • 2.x: /Library/Python/<version>/site-packages
    • 3.x: /usr/local/lib/python3.x/site-packages

Save Installed Package List

$ pip freeze > requirements.txt

Install from requirements list:

$ pip install -r requirements.txt