<< All Blog Posts
How to Set Up Python on Your New Mac

How to Set Up Python on Your New Mac

You just got a shiny new MacBook and are eager to start messing around with development tools, but where do you begin? Whether you are an experienced developer moving to macOS or are getting started with your first development computer, here are the basic things you should do to set up your Mac to develop using Python virtual environments.

One thing to know before starting: Don’t rely on the Python version that comes with macOS. Code developed using this version of Python is only relevant to this operating system, which limits the usability of whatever you develop. For more on this and other helpful tips, see Six Feet Up co-founder and CTO Calvin Hendryx-Parker’s helpful blog “The Zen of Python: Boostrapping Your Local Python Environment.”

Note that after installing some of the tools outlined below, you will need to open a new Terminal window before continuing.

Install Homebrew

Homebrew is a package manager that lays the groundwork for everything else you’ll need to get going. See the installation documentation for Homebrew to get started.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Homebrew also automatically installs command line tools.

Use Homebrew to install pyenv

This tool is essential to managing your Python versions across environments. Pyenv allows you to manage multiple versions of Python, which is helpful if you are working on projects that are based in different versions. With Homebrew, you can install it without having to use sudo, which is a recommended best practice.

Before you jump in with pyenv, be sure to configure your shell’s environment to run it. You can read more about that in GitHub’s documentation.

Install pyenv with a couple different Python versions:

$ brew install pyenv
$ pyenv install 3.7.12
$ pyenv install 3.10.2
$ pyenv global 3.10.2

Next, install pip to install and manage libraries written using Python. Here are the steps needed to install, along with lots of other useful information about pip.

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python3 get-pip.py

How to create environments

Virtual environments let you create isolated Python environments with their own directories that don’t share dependencies with other virtualenv environments.

python -m venv [folder_name]

Then, to create a virtualenv with a specific version of Python (after installing it with pyenv), you can do the following:

$ /Users/[yourusername]/.pyenv/versions/3.7.5/bin/python -m venv [folder_name]

Wait, there’s more?

Once you have Homebrew, you’ll almost certainly need the packages listed below (listed on one line so you can just select and drag it to a Terminal window as-is after $ brew install).

For more information on any of the packages, run brew desc <package(s)> for a description, brew info <package> for more detail, or brew home <package> to visit its home page.

git mailhog nmap openconnect postgresql rsync

Other packages that are nice to have, or that you may need for certain projects:

awscli fzf lnav moreutils mysql@5.7 nginx pwgen redis telnet the_silver_searcher tmux tree watch wget wv zsh-completions

Some projects unfortunately require Java. It can be installed with brew install java.

Finally, if you find yourself using installed services like PostgreSQL or MailHog often, you can keep them running whenever you’re logged in. See brew info <package> for the appropriate brew services command.

Thanks for filling out the form! A Six Feet Up representative will be in contact with you soon.

Connect with us