Skip to content

Instantly share code, notes, and snippets.

@eliangcs
Last active June 8, 2023 07:46
Show Gist options
  • Star 77 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save eliangcs/43a51f5c95dd9b848ddc to your computer and use it in GitHub Desktop.
Save eliangcs/43a51f5c95dd9b848ddc 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:

eval "$(pyenv init -)"

Install pyenv-virtualenvwrapper

brew install pyenv-virtualenvwrapper
pyenv virtualenvwrapper

Add the following to ~/.bash_profile:

export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"

Restart your shell or source your profile:

source ~/.bash_profile

Install pyenv-pip-rehash

git clone https://github.com/yyuu/pyenv-pip-rehash.git ~/.pyenv/plugins/pyenv-pip-rehash

Usage

List available Python versions you can install:

pyenv install --list

Install a Python version

pyenv install 2.7.8
pyenv install 3.4.1

See what Python versions you have installed:

pyenv versions

Switch Python versions globally or locally:

pyenv global 2.7.8
pyenv local 2.7.8

Create a virtualenv:

mkvirtualenv my-venv

Install a package with pip:

pip install ipython
@tiagoamx
Copy link

First you need to have installed virtualenvwrapper with pip
pip install virtualenvwrapper

@sdcharle
Copy link

You don't want to use mkvirtualenv with pyenv. It won't show up when you do 'pyenv virtualenvs' so that will be aggravating.

Something like this is the way to go:
pyenv virtualenv 3.6.3 espstuff

This guy's cheatsheet is nice: https://github.com/malexer/cheatsheets/blob/master/pyenv.md

@cpagravel
Copy link

Note that lsvirtualenv works to show the virtual environments made with mkvirtualenv. Seems nice :). Re: https://virtualenvwrapper.readthedocs.io/en/latest/command_ref.html

@adinneen
Copy link

adinneen commented Feb 20, 2020

For those newbies out there when it says "Add the following to ~/.bash_profile:" just add >>~/.bash_profile to the end of the command they list.

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