.bash
$ brew install pyenv pyenv-virtualenv pyenv-virtualenvwrapper
Add the following to .zshrc
.bash
$ vim .zshrc
export PYENV_ROOT="$HOME/.pyenv”
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)”
export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"
pyenv virtualenvwrapper
.bash
$ pyenv install -l
.bash
$ pyenv install 3.4.1
.bash
$ pyenv local 3.4.1
If not specified, system python will be used
.bash
$ pyenv global 3.4.1
When I open a new shell, it uses python set in global
.bash
$ python --version
Python 3.4.1
Contents of existing pip
.bash
$ pip list
argparse (1.2.2)
pbr (0.10.2)
pip (1.5.6)
setuptools (2.1)
six (1.8.0)
stevedore (1.1.0)
virtualenv (1.11.6)
virtualenv-clone (0.2.5)
virtualenvwrapper (4.3.1)
An environment is created with mkvirtualenv [environment name]
.bash
/Volumes/kobayashi/work% mkvirtualenv test
Using base prefix '/Users/kasei_san/.pyenv/versions/3.4.1'
New python executable in test/bin/python3.4
Also creating executable in test/bin/python
Installing setuptools, pip...done.
The environment name is displayed at the left end of the prompt (The contents of pip are cleared)
.bash
(test)/Volumes/kobayashi/work% pip list
pip (1.5.6)
setuptools (3.6)
.bash
$ workon testenv
.bash
$ workon
test
.bash
$ deactivate
.bash
$ rmvirtualenv test
Create an environment
.bash
$ mkvirtualenv playlist_to_mp3
Using base prefix '/Users/kasei_san/.pyenv/versions/3.4.1'
New python executable in playlist_to_mp3/bin/python3.4
Also creating executable in playlist_to_mp3/bin/python
Installing setuptools, pip...done.
Associate the current environment with the current directory with setvirtualenvproject
.bash
$ (playlist_to_mp3)/Users/kasei_san/Dropbox/work/playlist_to_mp3% setvirtualenvproject
Setting project for playlist_to_mp3 to /Users/kasei_san/Dropbox/work/playlist_to_mp3
.bash
$ pyenv local 2.7.9rc1
$ python --version
Python 2.7.9rc1
$ mkvirtualenv test
$ (test) python --version
Python 2.7.9rc1
Open a new shell
.bash
$ python --version
Python 3.4.1
$ workon test
$ (test) python --version
Python 2.7.9rc1
Confirm that the version changes
Recommended Posts