After a clean install of Marvericks, I revamped the python environment. In the past, virtualenv + virtualenvwrapper was enough. It's convenient because you can switch the python environment for each directory.
And although some of the same information was already written by my seniors, I decided to use it for myself.
pyenv
$ brew install pyenv
This is the end.
$ brew install pyenv-virtualenv
Just do this from the beginning and pyenv will come in with you.
As a precaution during installation, the following will be prompted as appropriate.
To enable shims and autocompletion add to your profile:
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
To use Homebrew's directories rather than ~/.pyenv add to your profile:
export PYENV_ROOT=/usr/local/opt/pyenv
$ pyenv install 2.7.6
The specified version of python is installed. Of course with pip.
To check the list of installable versions
$ pyenv install -l
If you want to check the list of installed environments
$ pyenv versions
I feel that this is personal or not. If you don't, just go to see python on the system side.
$ python --version;which python
Python 2.7.5
/usr/bin/python
$ pyenv global 2.7.6
$ exec $SHELL -l
$ python --version;which python
Python 2.7.6
/usr/local/opt/pyenv/shims/python
Introduced version 3.3.3 environment.
$ pyenv install 3.3.3
Move to an arbitrary directory and specify the environment.
$ cd ~/Projects/sandbox/
$ pyenv local 3.3.3
$ pyenv version
3.3.3 (set by /Users/xxx/Projects/sandbox/.python-version)
Confirm that you are looking at global except for the specified directory.
$ cd
$ pyenv version
2.7.6 (set by /usr/local/opt/pyenv/version)
virtualenv
Based on the environment for each version specified at the time of pyenv install
, virtualenv newly duplicates the environment.
This is convenient when you want to have the same version but different package configurations.
$ pyenv virtualenv 2.7.6 sandbox276
The environment created here is also included in pyenv versions
.
If you use pyenv local sandbox276
, you can use the environment in any directory as well.
The environment for each version is the same as the virtualenv environment.
$ pyenv uninstall 3.3.3
$ pyenv uninstall sandbox276
$ pyenv versions
system
* 2.7.6 (set by /usr/local/opt/pyenv/version)
However, if you specify local and create an environment in an arbitrary directory, a file called .python-version
will be created and the environment name will be written there, but please note that it will not disappear.
Vertically flexible version! Flexible sideways with virtualenv! Surely convenient!
Recommended Posts