Skip to content
How to setup python environment on macOS
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

How to setup python environment on macOS

On this page I describe how to setup python environment on macOS Mojave (10.12).

Know issues

When I recently upgraded to newer version of macOS I found few issues on my MacBook. Read below about issues and solutions to them.

Interestengly, but the same (or similar) issues was before, when I've upgraded to macOS Capitan and macOS Mavericks.

Bad file permissions

Repair disk permissions with Disk Utility. It happens that permissions on some files and directories broken after upgrade to newer version of macOS.

Then run next command to make this directory writable:

sudo chown -R $(whoami) $(brew --prefix)/*

Previously it was possible to do like this sudo chown -R $(whoami):admin /usr/local but no anymore.

Homebrew doen't work

Fix issue with these commands:

xcode-select --install
cd /usr/local/Library
git pull origin master

You can try to find some problems by running:

brew doctor

Python doesn't work

brew reinstall python
brew reinstall python@2

See also list of known bugs in HomeBrew.

Ruby gems can't be installed

To install ruby gems, use this command:

sudo gem install -n /usr/local/bin [package]

where [package] is what you need to install (compass, bundler, etc).


Before you start, open Terminal application and install Xcode command-line tool. It's required to install a lot of software on your Mac.

xcode-select --install

Install HomeBrew to have ability to install up-to-date software, like apt-get install in Ubuntu.

My list of brew software (use brew install [package_name]):

  • required: memcached, git, mysql, postgresql, node, wget
  • optional: mercurial, mongodb, rabbitmq, zookeeper --with-python, boost --with-python, jpeg, libpng

System changes

Edit nano ~/.profile file and insert this content.

Press Cmd + O to save file, Cmd + X to exit from nano. Run in terminal source ~/.profile to load changes.

If you use mercurial

Edit ~/.hgrc and insert info about my user:

username = User Name <>


  • brew install python installs python and pip
  • pip install virtualenv virtualenvwrapper

Python virtualenv

If your virtual environments are broken, then you need to recreate links to the newer version of Python.

Do these two commands for each of your project:

# delete all broken links
find ~/.virtualenvs/my_project_name/ -type l -delete
# create new links to python
virtualenv ~/.virtualenvs/my_project_name/

Python 3 support

  • brew install python3 installs python3 and pip3
  • pip3 install virtualenv virtualenvwrapper

To create virtual environment with python3 support you need to specify path to specific version of python.

mkvirtualenv --python=$(which python3) project_name
# you can also use my shortcut from ~/.profile (see link to file above)
mkvirtualenv3 project_name

Django completion

Add autocompletion in terminal when we type or and press <tab> button two times.

  • cd /usr/local/etc/bash_completion.d/
  • wget
  • source ~/.profile to affect changes


  • create virtual environments for projects mkvirtualenv [env_name] and run pip install -r requirements.txt
  • restore MySQL/Postgres/MongoDB databases
    • mongodb: mongodump --out backup/ -> mongorestore backup/


This is my list of sofrware that I use:

Setup OS X integration with web sites

Read also

You can’t perform that action at this time.