Skip to content

Instantly share code, notes, and snippets.

@sarveshseri
Last active December 20, 2020 22:19
Show Gist options
  • Save sarveshseri/3b32f3485248141e008eb61bce2942ac to your computer and use it in GitHub Desktop.
Save sarveshseri/3b32f3485248141e008eb61bce2942ac to your computer and use it in GitHub Desktop.
Python Related

Install Python 3

Install python 3 with homebrew. This will also setip pip for us.

brew install python

Add new installed python to the top of your Path

export PATH="/usr/local/opt/python/libexec/bin:$PATH"

Install vritualenv

Install with pip .

pip install virtualenv
pip install virtualenvwrapper

Add following to your .bashrc or .zprofile .

export PATH="/usr/local/opt/python/libexec/bin:$PATH"

export WORKON_HOME=$HOME/.virtualenvs

export VIRTUALENVWRAPPER_PYTHON=/usr/local/opt/python/libexec/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv

source /usr/local/bin/virtualenvwrapper.sh

Using virtualenv

# Create a virutal env in $WORKON_HOME
mkvirtualenv my_env

# Exit out of the current Python virtual environment
deactivate

# List available virtual environments
workon 

# Activate the specified Python virtual environment
workon name_of_environment

# Remove the specified environment
rmvirtualenv name_of_environment

pipenv is slow... really slow...

Pipenv

pipenv can be thought of as the missing project package manager for python.

Its an improved and feature rich alternative to the older pip + requirements.txt combination.

It creates Pipfile and Pipfile.lock files which keep track of dependencies required for the project.

Install

pip install pipenv

Usage

# to install and add a dependency
pipenv install django

# to install and add a dependency with specific version
pipenv install django==3.0.8

# to install and add a dev-dependency
pipenv install pytest --dev

# to generate/update lockfile
pipenv lock

# install project dependencies
pipenv install

# install project dev-dependencies
pipenv install --dev

# install locked project dependencies
pipenv install --ignore-pipfile

# check the dependency graph
pipenv graph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment