Skip to content

Instantly share code, notes, and snippets.

@c17r
Last active June 9, 2016 17:44
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 c17r/21a414f8fd5fb1eca59b031537f7c385 to your computer and use it in GitHub Desktop.
Save c17r/21a414f8fd5fb1eca59b031537f7c385 to your computer and use it in GitHub Desktop.
Ubuntu 14.04, pyenv globally w/ 2.7.11 & 3.5.1, filesystem-style venvs & virtualenvwrapper-style venvs

As Admin

# sudo apt-get install git python-pip make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev
# pip install virtualenv virtualenv-clone virtualenvwrapper

# git clone https://github.com/yyuu/pyenv.git /opt/pyenv
# git clone https://github.com/yyuu/pyenv-virtualenvwrapper.git /opt/pyenv/plugins/py-virtualenvwrapper

# cat << 'EOF' >> /etc/bash.bashrc
# pyenv global
if [ -d /opt/pyenv ]; then
        export PYENV_ROOT="/opt/pyenv"
        export PATH="$PYENV_ROOT/bin:$PATH"
        eval "$(pyenv init -)"
        pyenv virtualenvwrapper
fi

# exec "$SHELL"

# pyenv install 3.5.1
# pyenv install 2.7.1
EOF

As Any User

$ mkdir ~/test/ && cd ~/test/
$ venv fs-venv-2 -p $(pyenv prefix 2.7.11)/bin/python
$ venv fs-venv-3 -p $(pyenv 3.5.1)/bin/python
$ ls
fs-venv-2 fs-venv-3
$ python --version
Python 2.7.6
$ source fs-venv-2/bin/activate
(fs-venv-2) $ python --version
Python 2.7.11
(fs-venv-2) $ deactivate
$ source fs-venv-3/bin/activate
(fs-venv-3) $ python --version
Python 3.5.1
(fs-venv-3) $ deactivate
$ 

$ mkvirtualenv vew-2 -p $(pyenv prefix 2.7.11)/bin/python
(vew-2) $ python --version
Python 2.7.11
(vew-2) $ deactivate
$ mkvirtualenv vew-3 -p $(pyenv prefix 3.5.1)/bin/python
(vew-3) $ python --version
Python 3.5.11
(vew-3) $ deactivate
$ 

Note

As a regular user, if you pyenv shell 2.7.11 or pyenv shell 3.5.1 and then try to pip install into the global space, it will give a permission denied error which I think is a good thing! Forces regular users to use a venv of some kind.

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