Catalina Python3

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.

Python 3 is developing steadily, and releasing new updates regularly. That makes it important for me to regularly get those updates. Recently, I tried to run a project on macOS that depended on Python 3.5.9, a version that I did not have installed on my system. However, I notice you mention that you are using IDLE from Python 3.7.3. If so, be aware that that is not the latest release of either Python 3 or Python 3.7 (3.7.3 predates Catalina.) 3.7.7 is the most recent for 3.7 but Python 3.8 is now current and its most recent release, 3.8.3, has the most up-to-date support for 10.15. Note: macOS Catalina includes Python3 by default. The most recent version is 3.7.3! $ xcrun python3 Python 3.7.3 (default, Mar 6 2020, 22:34:30). Build pyenv Python versions on macOS Catalina 10.15. 19 February 2020 9 comments Python. Installing Python-3.5.10. Python-build: use readline from homebrew. Using Python on a Macintosh¶ Author. Bob Savage Python on a Macintosh running Mac OS X is in principle very similar to Python on any other Unix platform, but there are a number of additional features such as the IDE and the Package Manager that are worth pointing out.

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.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:

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:

Catalina Python3

So, for Python 3.y.z, you’ll find it at /usr/local/lib/python3.y/site-packages.

Catalina Python3

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?

Formulae that declare an unconditional dependency on the 'python' formula are bottled against Homebrew’s Python 3.x and require it to be installed.

Posted on October 4, 2016 by Paul

Updated 15 June 2021

In this article, I will show you how to install Python with NumPy, SciPy and Matplotlib on macOS Big Sur.

I assume you are on an Intel based Mac. If you have an arm64 Mac, also called Apple Silicon, please check my other article.

MacOS Big Sur comes by default with Python 2.7 which, at this point, receives only bug fixes and is EOL since 2020. Python 3 is the future and it is supported by all major Python libraries. In this tutorial, we’ll use Python 3.9 which is the latest stable release of Python at the time of this writing.

Start by installing the Command Line Tools for macOS. Please note, that you will need the Command Line Tools even if you’ve already installed Xcode. Open a Terminal and write:

インストール

Once the Command Line Tools are installed, we can install Python.

As a side note, after you install the Command Line Tools, you will also get a slightly older Python 3 version (3.8). In this article, we are going to use the latest stable version of Python which, at the time of this writing is 3.9.

Go to https://www.python.org/ and download Python. The official installer of Python is a pkg file that will start a GUI installer which will guide you through the installation.

You can have multiple Python 3 versions installed on your macOS machine. If this is the case, you can select which version you want to use by specifying the version number, e.g.:

or:

Mac Catalina Python3 Default

After the above, you can invoke Python 3.9 using the python3.9 command. python3 will also invoke the latest installer version of Python 3. This is what I see if I run python3.9 on my machine:

Next, let’s follow best practices and create a new Python environment, named work (feel free to use a different name), in which we can install NumPy, SciPy and Matplotlib:

At this point, your prompt should indicate that you are using the work environment. You can read more about Python environments in the documentation.

Once an environment is activated, all the install commands will apply only to the current environment. By default, if you close your Terminal, the environment is deactivated. If you want to be able to use it, use the source work/bin/activate command.

We can install NumPy, SciPy and Matplotlib with:

As a side note, when you are in an active environment you can use the python command to invoke the Python interpreter, no need to use the version number.

Fire up Python, import scipy and print the version of the installed library. This is what I see on my machine:

Let’s try something a bit more interesting now, let’s plot a simple function with Matplotlib. First, we’ll import NumPy and Matplotlib with:

Next, we can define some points on the (0, 1) interval with:

Now, let’s plot a parabola defined on the above interval:

You should see something like this:

As you’ve probably noticed, plt.show() is a blocking command. You won’t be able to use the interpreter until you close Figure 1.

There is also an interactive mode in which you can plot functions. Close Figure 1 and write:

This is what you should see:

At any point you can disable the interactive plot mode with:

after which you will need to use the plt.show() function in order to actually see the result of the plt.plot function.

Catalina Python 3

If you want to learn more about Python and Matplotlib, I recommend reading Python Crash Course by Eric Matthes. The book is intended for beginners, but has a nice Data Visualization intro to Matplotlib chapter:

Catalina

Another good Python book, for more advanced users, which also uses Matplotlib for some of the book projects is Python Playground by Mahesh Venkitachalam:


Show Comments