Skip to content

Instantly share code, notes, and snippets.

@mkwatson
Forked from tiagoamx/pyenv+virtualenv.md
Last active February 3, 2020 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkwatson/3985fa9be75f253c45284a91f4cd5cdc to your computer and use it in GitHub Desktop.
Save mkwatson/3985fa9be75f253c45284a91f4cd5cdc to your computer and use it in GitHub Desktop.
Cheatsheet: pyenv, virtualenvwrapper, and pip

Cheatsheet: pyenv, virtualenvwrapper, and pip

Installation (for Mac OS)

Install pyenv with brew

brew update
brew install pyenv

Add the following line to ~/.bash_profile (or ~/.zshrc):

eval "$(pyenv init -)"

Install pyenv-virtualenvwrapper

brew install pyenv-virtualenvwrapper
pyenv virtualenvwrapper

Add the following to ~/.bash_profile (or ~/.zshrc):

export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"

Restart your shell or source your profile:

source ~/.bash_profile

or

source ~/.zshrc

Usage

List available Python versions you can install:

pyenv install --list

Install a Python version

pyenv install 3.7.6
pyenv install 3.8.1

See what Python versions you have installed:

pyenv versions

Switch Python versions globally or locally:

pyenv global 3.7.6
pyenv local 3.8.1

Creating a local version for a project should create a .python-version file with the project version (this should be checked in)

Create a virtualenv:

mkvirtualenv my-venv

Install a package with pip:

pip install ipython

Capture dependancies in git:

pip freeze > requirements.txt
git add requirements.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment