I needed to use python for my research, so I will share the contents of the environment construction. First of all, in the case of mac, python2.7 is included in the system from the beginning.
pyenv You can manage multiple versions of python. It's like rbenv in Ruby.
We will install it immediately. There are several installation methods, but this time I will install it with Homebrew.
$ brew install pyenv
Then put it in your PATH.
.bash_profile
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
$ source ~/.bash_profile
You can see the list of installable pythons.
$ pyenv install -l
Anaconda Then install Anaconda. This is a package that allows you to install various packages in a batch in addition to python itself. Install using pyenv. This time, we will build the environment with version 2.x.
$ pyenv install anaconda-2.4.0
Now you have 2.x anaconda! This anaconda contains python2.7.
$ pyenv global anaconda-2.4.0
$ python --version
Python 2.7.12 :: Anaconda custom (x86_64)
By specifying the installed anaconda, it became anaconda python instead of the system! If you check the version of python, it will be Python 2.7.12.
Next, I will build a virtual environment with anaconda. Development will be done in this virtual environment. If something happens, you can easily reset it and feel safe!
There is also a virtualenv to build a virtual environment with python, but you can also build a virtual environment with anaconda using something called conda!
$ conda create -n [The name of the virtual environment] python=2.7
You can easily build a virtual environment with this command.
$ conda env list
You can check the existing virtual environment with this command.
source activate [The name of the virtual environment]
source deactivate
You can enter the virtual environment with activate! Deactivate when you leave!
I stumbled once when activating. The problem is that pyenv and condo activate conflict!
http://qiita.com/y__sama/items/f732bb7bec2bff355b69
Let's add PATH.
We built a python environment this time! Compared to other languages, there are many things such as package management and version control, which makes me confused! pyenv => anaconda => virtual environment Like, the structure has many layers, but I think it could be made easier, especially if one environment is good. I'm glad I just had anaconda ...
That's all for building the python environment.
Recommended Posts