Mac OS X comes with Python 2.7 out of the box.
You do not need to install or configure anything else to use Python 2. Theseinstructions document the installation of Python 3.
$ brew install python. If there are problems related to the pip usage we may need to relink the python with the following command. $ brew unlink python && brew link python Check and Display Pip Version. We can check installed pip version with the -V or -version option like below. $ pip -V $ pip3 -V. Right after installed python using brew, 'which python' give me the correct local python path, but 'python' command indicated that it was the system installed one invoking. Restart terminal fixed it. – Michelle Feb 20 '17 at 6:50. By the way, if you're wondering why I keep referring to Python 3.x – the x is a stand-in for sub-versions (or point releases as developers call them.) This means any version of Python 3. How to Install Homebrew on Mac. First you need to install Homebrew, a powerful package manager for Mac. Open up your terminal.
The version of Python that ships with OS X is great for learning, but it’s notgood for development. The version shipped with OS X may be out of date from theofficial current Python release,which is considered the stable production version.
Doing it Right¶
Let’s install a real version of Python.
Before installing Python, you’ll need to install GCC. GCC can be obtainedby downloading Xcode, the smallerCommand Line Tools (must have anApple account) or the even smaller OSX-GCC-Installerpackage.
Note
If you already have Xcode installed, do not install OSX-GCC-Installer.In combination, the software can cause issues that are difficult todiagnose.
Note
If you perform a fresh install of Xcode, you will also need to add thecommandline tools by running xcode-select--install
on the terminal.
While OS X comes with a large number of Unix utilities, those familiar withLinux systems will notice one key component missing: a package manager.Homebrew fills this void.
To install Homebrew, open Terminal
oryour favorite OS X terminal emulator and run
The script will explain what changes it will make and prompt you before theinstallation begins.Once you’ve installed Homebrew, insert the Homebrew directory at the topof your PATH
environment variable. You can do this by adding the followingline at the bottom of your ~/.profile
file Acer hs-usb diagnostics driver download for windows.
If you have OS X 10.12 (Sierra) or older use this line instead
Now, we can install Python 3:
This will take a minute or two.
Pip¶
Homebrew installs pip
pointing to the Homebrew’d Python 3 for you.
Working with Python 3¶
At this point, you have the system Python 2.7 available, potentially theHomebrew version of Python 2 installed, and the Homebrewversion of Python 3 as well.
will launch the Homebrew-installed Python 3 interpreter.
Alcatel one touch 8008x driver download for windows 10. will launch the Homebrew-installed Python 2 interpreter (if any).
will launch the Homebrew-installed Python 3 interpreter.
If the Homebrew version of Python 2 is installed then pip2
will point to Python 2.If the Homebrew version of Python 3 is installed then pip
will point to Python 3.
The rest of the guide will assume that python
references Python 3.
Pipenv & Virtual Environments¶
The next step is to install Pipenv, so you can install dependencies and manage virtual environments.
A Virtual Environment is a tool to keep the dependencies required by different projectsin separate places, by creating virtual Python environments for them. It solves the“Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keepsyour global site-packages directory clean and manageable.
For example, you can work on a project which requires Django 1.10 while alsomaintaining a project which requires Django 1.8.
So, onward! To the Pipenv & Virtual Environments docs!
This page is a remixed version of another guide,which is available under the same license.
This page describes how Python is handled in Homebrew for users. See Python for Formula Authors for advice on writing formulae to install packages written in Python.
Homebrew should work with any CPython and defaults to the macOS system Python.
Homebrew provides formulae to brew Python 3.x.
Homebrew provided a python@2
formula until the end of 2019, at which point it was removed due to the Python 2 deprecation.
Important: If you choose to use a Python which isn’t either of these two (system Python or brewed Python), the Homebrew team cannot support any breakage that may occur.
Python 3 Brew Install
Python 3.x
Homebrew provides a formula for Python 3.x (python@3.x
).
Important: Python may be upgraded to a newer version at any time. Consider using a versionmanager such as pyenv
if you require stability of minor or patch versions for virtual environments.
The executables are organised as follows:
python3
points to Homebrew’s Python 3.x (if installed)pip3
points to Homebrew’s Python 3.x’s pip (if installed)
Unversioned symlinks for python
, python-config
, pip
etc. are installed here: Usb 2.0 dvbt ez loader driver download.
Setuptools, Pip, etc.
The Python formulae install pip (as pip3
) and Setuptools.
Setuptools can be updated via pip3, without having to re-brew Python:
Similarly, pip3 can be used to upgrade itself via:
site-packages
and the PYTHONPATH
The site-packages
is a directory that contains Python modules (especially bindings installed by other formulae). Homebrew creates it here:
So, for Python 3.y.z, you’ll find it at /usr/local/lib/python3.y/site-packages
.
Python 3.y also searches for modules in:
/Library/Python/3.y/site-packages
~/Library/Python/3.y/lib/python/site-packages
Homebrew’s site-packages
directory is first created if (1) any Homebrew formula with Python bindings are installed, or (2) upon brew install python
.
Why here?
The reasoning for this location is to preserve your modules between (minor) upgrades or re-installations of Python. Additionally, Homebrew has a strict policy never to write stuff outside of the brew --prefix
, so we don’t spam your system.
Homebrew-provided Python bindings
Some formulae provide Python bindings.
Warning! Python may crash (see Common Issues) if you import <module>
from a brewed Python if you ran brew install <formula_with_python_bindings>
against the system Python. If you decide to switch to the brewed Python, then reinstall all formulae with Python bindings (e.g. pyside
, wxwidgets
, pygtk
, pygobject
, opencv
, vtk
and boost-python
).
Policy for non-brewed Python bindings
These should be installed via pip install <package>
. To discover, you can use pip search
or https://pypi.python.org/pypi.
Note: macOS’s system Python does not provide pip
. Follow the pip documentation to install it for your system Python if you would like it.
Brewed Python modules
For brewed Python, modules installed with pip3
or python3 setup.py install
will be installed to the $(brew --prefix)/lib/pythonX.Y/site-packages
directory (explained above). Executable Python scripts will be in $(brew --prefix)/bin
.
The system Python may not know which compiler flags to set in order to build bindings for software installed in Homebrew so you may need to run:
Virtualenv
WARNING: When you brew install
formulae that provide Python bindings, you should not be in an active virtual environment.
Activate the virtualenv after you’ve brewed, or brew in a fresh terminal window.Homebrew will still install Python modules into Homebrew’s site-packages
and not into the virtual environment’s site-package.
Virtualenv has a --system-site-packages
switch to allow “global” (i.e. Homebrew’s) site-packages
to be accessible from within the virtualenv.
Why is Homebrew’s Python being installed as a dependency?
Python3 Brew 2
Formulae that declare an unconditional dependency on the 'python'
formula are bottled against Homebrew’s Python 3.x and require it to be installed.