Skip to content

Instantly share code, notes, and snippets.

@rosswd
Last active March 5, 2018 01:54
Show Gist options
  • Save rosswd/ada677a48e81c2f37540230967346f5d to your computer and use it in GitHub Desktop.
Save rosswd/ada677a48e81c2f37540230967346f5d to your computer and use it in GitHub Desktop.
Using pip, virtualenv and/or virtualenvwrapper to manage packages and environments in python.
# know what version of python you have
python # os (2.7.10)
python2 # homebrew python 2 (2.7.14)
python3 # homebrew python 3 (3.6.2)
# install pipenv
pip3 install pipenv
export PATH=$PATH:$HOME/Library/Python/3.6/bin >> ~/.bash_exports
# use
mkdir myproject
cd myproject
pipenv install requests
vim main.py
pipenv run python main.py
cat Pipfile
#pipenv shell
# project directory and environment creation
# one time set up for project setup
vim .bash_profile
export PROJECT_HOME=$HOME/Sites/python
source .bash_profile
# workflow for project
mkproject webthingy
deactivate
# managing environments
rmvirtualenv <venv>
lsvirtualenv
# using virtualenv
# one time set up for virtualenv
pip install virtualenv
# workflow for virtualenv
mkdir <project_name>
cd <project_name>
virtualenv <some-env>
cd <some-env>
source bin/activate
pip install <package1 package2 etc>
pip freeze > requirements.txt
deactivate
# one time set up for virtualenvwrapper
pip install virtualenvwrapper
export WORKON_HOME=~/Envs
source /usr/local/bin/virtualenvwrapper.sh
source ~/.bash_profile
# workflow for virtualenvwrapper
mkvirtualenv webscrape-stack
pip install requests beautifulsoup4
pip freeze > requirements.txt
deactivate
workon webscrape-stack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment