Skip to content

Instantly share code, notes, and snippets.

@bartmika
Last active November 17, 2016 10:16
Show Gist options
  • Save bartmika/fee2f40f9ce73a8a9cac8e8087b4165b to your computer and use it in GitHub Desktop.
Save bartmika/fee2f40f9ce73a8a9cac8e8087b4165b to your computer and use it in GitHub Desktop.
A HOWTO guide for setting up Python 3.x+ on MacOS.

Setup brew, Python 3, Pip, VirtualEnv, Postgres, gettext, memcached, SSH in MacOS Sierra

By: Bartlomiej Mika at https://mikasoftware.com Date: Oct, 13th, 2016

brew

  1. Install Xcode from the Apple App Store.

  2. Install the Command Line Tools of Xcode. Open a Terminal and type:

$ xcode-select --install
  1. Next, we need to install Homebrew. In the Terminal, type this command line:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  1. Now, we need to insert the Homebrew directory at the top of the PATH environment variable. In this way, some Homebrew installations will take precedence over stock OS X binaries. Open or create the file ~/.bash_profile and write:
export PATH=/usr/local/bin:$PATH
  1. Close your Terminal and open it again to make these changes effective.

Python 3+

  1. Install python 3 (latest)
$ brew install python3
  1. You can check which version is installed by typing
$ python3 --version
  1. Verify latest is installed:
$ python3

Pip

sudo easy_install pip

Virtualenv

Q: What is it? A: Python packages installed via the steps above are global in the sense that they are available across all of your projects. That can be convenient at times, but it can also create problems. For example, sometimes one project needs the latest version of Django, while another project needs an older Django version to retain compatibility with a critical third-party extension. This is one of many use cases that virtualenv was designed to solve. On my systems, only a handful of general-purpose Python packages (such as Mercurial and virtualenv) are globally available — every other package is confined to virtual environments.

  1. To install:
$ sudo pip install virtualenv
  1. Create some directories to store our projects and virtual environments, respectively:
$ mkdir -p ~/Developer ~/Virtualenvs
  1. We’ll then open the ~/.bashrc file (which may be created if it doesn’t exist yet)…
$ vi ~/.bashrc

And add some lines to it:

# pip should only run if there is a virtualenv currently activated
export PIP_REQUIRE_VIRTUALENV=true
# cache pip-installed packages to avoid re-downloading
export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
  1. Let’s re-load our bash environment:
$ source ~/.bash_profile

Postgres

  1. Install library for pip.
brew install postgresql
  1. Download for OSX: http://postgresapp.com

  2. Copy into /Applications

  3. Run it

  4. Postgres.app includes many command line tools. If you want to use them, you must configure the $PATH variable. If you are using bash (default shell on OS X), add the following line to ~/.bash_profile:

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin

SSH Keys

  1. Generate SSH key for account.
mkdir ~/.ssh/;
cd ~/.ssh/;
ssh-keygen -t rsa;
  1. Print the SSH key and copy it to whatever service you us.
cat ~/.ssh/id_rsa.pub;

gettext

Using brew to install the app.

brew install gettext
brew link gettext --force

memcached

  1. Run the following command:
brew install memcached
brew install libmemcached
brew install lzlib
  1. To startup the cache, run the following.
/usr/local/bin/memcached -d -u nobody

Soures

  1. https://www.computersnyou.com/2960/setup-django-virtualenv-macosx-mavericks/
  2. http://stackoverflow.com/questions/20251562/how-to-install-django-for-python-3-3
  3. http://hackercodex.com/guide/python-development-environment-on-mac-osx/
  4. http://stackoverflow.com/questions/12410113/migrating-virtualenv-and-github-between-computers
  5. http://www.postgresqlforbeginners.com/2010/11/interacting-with-postgresql-psql.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment