Mac OS X comes with Python 2.7 out of the box.
- Install Xcode Command Line Tools
- Reinstall Xcode Command Line Tools
- Xcode Brewing Company
- Brew Xcode Outdated
You can install Xcode, the CLT, or both; Homebrew supports all three configurations. Downloading Xcode may require an Apple Developer account on older versions of Mac OS X. Sign up for free here. 4 The one-liner installation method found on brew.sh requires a Bourne-compatible shell (e.g. Notably, fish, tcsh and csh will not work. Documentation for the missing package manager for macOS. Brew install Upgrading Homebrew and its packages can be done just as easily: brew upgrade. But running this on Big Sur, with the latest version of Xcode (12.2) installed via the App Store will throw this error: Your CLT does not support macOS 11.0.
You do not need to install or configure anything else to use Python 2. Theseinstructions document the installation of Python 3.
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.
Install Xcode Command Line Tools
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.
Reinstall Xcode Command Line Tools
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
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.
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.
As discussed on recent episodes of ATP, I’ve had some issues with my iMaclately. A trip to the Apple Store and new logic board later, I had functionalhardware but no software installed upon it. Finally, I had the opportunity totry out something I’ve been preparing for a long while: my Brewfile
.
Much in the spirit of Ruby’s Bundler, Homebrew has Bundle.For both Bundler and Bundle, you provide a file with a list of software/dependenciesyou want installed, and the apps will install them automatically. In the caseof Bundler, it’s all Ruby gems; in the case of Bundle, it’s command line apps,Mac apps, and even fonts.
Last week, I loaded up my iMac from scratch using a Brewfile
I had been addingto over the last couple years. Finally getting the opportunity to use it hasgiven me the opportunity to refine it.
These refinements ended up being extremely convenient, as just yesterday Idecided to nuke my MacBook and reload it to try to get it operating properly.Thanks to Bundle, that took considerably less time than it would have inyears past.
All it took was having ~/Brewfile
, and then running
Give it a bit of time — a lot if you’re installing Xcode — andjust like that most/all of your favorite software is installed. All in oneeasy peasy command line incantation.
I can’t overstate how much time this has saved me. 🥳
Furthermore, as I add new items to my Brewfile
, I can feel free to runbrew bundle install
again. It will automatically skip software that’salready installed. In fact, the screen shot above was me re-running Bundlelong after it had worked its magic.
Your Brewfile
is unique to you; it’s a distillation of your own particulartoolchains and requirements. There are many like it, but this one is mine.
UPDATED 2019-10-09 3:00 PM: Several people have asked “okay, but, how do Icreate a Brewfile
to begin with?”
For me, I went spelunking through /Applications
to see what I had and what Iknew I couldn’t live without. Generating my Brewfile
from scratch was, to nosmall degree, the point.
Xcode Brewing Company
If you’d like to take a shortcut to get yourself started, you can do:
brew bundle dump
Brew Xcode Outdated
This will create a Brewfile
of everything Bundle recognizes on your existingsystem. At that point, you can go through and cull what you don’t think youreally need.