Skip to content

Instantly share code, notes, and snippets.

@css459
Created May 21, 2020 18:05
Show Gist options
  • Save css459/913404b189624a3091e0601222e15927 to your computer and use it in GitHub Desktop.
Save css459/913404b189624a3091e0601222e15927 to your computer and use it in GitHub Desktop.
How to set up a Python Environment Professionally

Using virtualenv (for when you don't need every package)

Install Requirements

  1. Install Python 3 and Pip (Install Pip)
  2. Check that python 3 is installed: which python3
  3. Install virtualenv (https://sourabhbajaj.com/mac-setup/Python/virtualenv.html)

Set up your env

Terminal

  1. cd into your project directory
  2. Make a file requirements.txt listing every external module you need. One on each line.
  3. Make your virtualenv: virtualenv venv --python=$(which python3)
  4. Activate the environment: source venv/bin/activate
  5. Install the requirements: pip install -r requirements.txt
  6. Run your python script python ...
  7. Deactivate the environment when you're done: deactivate (You can always reactivate with step 4)

PyCharm

  1. File --> Settings --> Search "Project Interpreter"
  2. Click the settings cog on upper right --> Click add
  3. Make sure you're in "virtualenv envrionment" submenu (see left pane)
  4. Select New Envrionment --> Select base interpreter to be some Python3 interpreter
  5. Make your requirements.txt file as above.
  6. Click "install requirements" while you're in that file and you're editing (PyCharm will warn you of uninstalled deps)

If you need Everything: Anaconda

https://www.anaconda.com/

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