Skip to content

Python Setup

Contents:

Installing Python with Homebrew

brew install python

[Optionally], you can alias python3 to just python by adding to your .zshrc or equivalent:

alias python='python3'
alias pip='pip3'

Virtual ENV Install / Config

Using virtual environments is recommended to avoid mismatched dependencies between projects. For this, we use virtualenvwrapper, which builds upon virtualenv.

pip install virtualenv

pip install virtualenvwrapper

Complete the setup according to their latest docs.

Then you need to adjust your .zshrc (or equivalent) to source virtualenvwrapper when starting your shell:

# PYTHON VIRTUALENVWRAPPER SETUP ==============================================

export VIRTUALENVWRAPPER_PYTHON=/opt/homebrew/bin/python3 # Adjust for your system / architecture
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Projects                        # Your default project dir
source /opt/homebrew/bin/virtualenvwrapper.sh             # Adjust for your system / architecture

Note: These values are for an M1 MacBook Pro, and might be different in other environments, particularly the /opt/homebrew/bin path. You can find where this ended up by running find / -name virtualenvwrapper.sh (source).

Usage

To create / activate / deactivate a virtual environment:

# create a new environment
mkvirtualenv <project_name>

# switch to some other environment
workon <some_other_project_name>

# and then to deactivate:
deactivate

Most shells will show some sort of indication of what virtual env you are in.

Installing Python on Windows

To install Python for Windows, go to the Python website here and download Python and its accompanying IDLE.

Navigate then to this website to find step by step instructions on how to download PIP onto your computer.

Installing PIP on Windows

  1. First, download the get-pip.py installation script. The binary data is a base85 encoding of a zip file containing the entire copy of pip. Select the entire page with CTRL+A and CTRL+C and paste it into a Python .py file. Save the file as get-pip.py in the same folder as your Python program is stored in.

  2. In a CMD prompt / Bash terminal, 'cd' to the path where the new get-pip.py file is saved

    $ cd C:/Users/john/AppData/Local/Programs/Python/Python310
    
  3. Run the command python get-pip.py in the terminal and then pip will begin installing.

    $ python get-pip.py
    Successfully installed pip-22.3.1
    
  4. Once pip has successfully installed, run the command pip -V to verify the installation process.

    $ pip -V
    pip 22.3.1 from C:/Users/...
    

Installing Python Dependencies using pip

In your CMD prompt / Bash terminal 'cd' to where the dev-docs repository is cloned in your computer. Run the command below to install required programs.

$ pip install -r REQUIREMENTS.txt