Skip to content

Instantly share code, notes, and snippets.

@danielkelshaw
Last active October 27, 2020 14:28
Show Gist options
  • Save danielkelshaw/4e540fb336f4cbe8d89748732af7ebd2 to your computer and use it in GitHub Desktop.
Save danielkelshaw/4e540fb336f4cbe8d89748732af7ebd2 to your computer and use it in GitHub Desktop.

Python Setup Guide

This Gist will just go through the basics of setting up Python in such a way that it is easily maintainable.

Table of Contents:

Making Life Easier

On Windows download a copy of Cygwin. This is a UNIX emulator for Windows which is much easier in my opinion.

Downloading Python

It is easy enough to go to the Python website and download the latest version of Python - but this does not necessarily play nicely with your system's version of Python. It also makes it much more difficult to run different versions of Python. There are two methods which can be used to install Python properly, Anaconda and PyEnv.

My preference is to use PyEnv - but Anaconda might be easier to set up on Windows.

Anaconda

Anaconda can be installed from this website.
Note: Make sure you download the 64-Bit version.

Conda provide a great starting guide which you can find here.

There is also a useful cheatsheet which can be found here

PyEnv

Anaconda is quite a large package which includes lots of unnecessary add-ons. Peronsally, I prefer to use PyEnv - this has the added benefit that it's super easy to switch between different versions of Python.

Installing on MacOS:

PyEnv can easily be installed using the brew package manager:

$ brew update
$ brew install pyenv

You should also install the Python dependencies:

$ xcode-select --install
$ brew install openssl readline sqlite3 xz zlib

Alternatively you can run a script I developed: setup_python.sh

Add PyEnv to PATH:

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc

Add pyenv init to your shell:

$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.zshrc

Restart your shell so the changes can take place. You can either restart the terminal or run the command:

$ exec "$SHELL"

Installing Python:

Now PyEnv has been installed, a relevant Python version can be installed:

$ pyenv install 3.8.5

You can now set this to be your global Python version:

$ pyenv global 3.8.5

Next Steps

Now you have Python installed it's time to take a look at using virtual environments...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment