Use pyenv and virtualenv on Mac to build a python development environment that can switch versions and installation libraries.
Install pyenv and virtualenv with homebrew. (I referred to here.)
pyenv / virtualenv installation
$ brew install pyenv
$ brew install pyenv-virtualenv
Put the path in .bash_profile.
.bash_profile
PYENV_ROOT=~/.pyenv
export PATH=$PATH:$PYENV_ROOT/bin
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Install python with pyenv.
python install
$ pyenv install 3.6.2
If an error occurs here, try executing the following command.
Command to try when python installation error
$ xcode-select --install
Now try installing python again. If it doesn't work, ask Google teacher ... (sweat)
In the case of mac, python 2.7 is installed, so switch to 3.6.2 with this installed.
From python version confirmation to switching
$ pyenv versions
* system
3.6.2
$ pyenv global 3.6.2
$ pyenv versions
system
* 3.6.2 (set by ・ ・ ・ ・)
$ python -V
Python 3.6.2
Build an environment as a trial.
Create an environment with virtualenv
$ mkdir project1
$ cd project1
$ pyenv virtualenv 3.6.2 project1
$ pyenv local project1
(project1) $
When the environment changes, the environment will be displayed before the prompt. The part of (project1). When there is nothing, system is selected.
If you move from the created directory, you can see that the environment changes.
Environmental change confirmation
(project1) $ cd ..
$ cd project1
(project1) $
Python environment construction on Mac (pyenv, virtualenv, anaconda, ipython notebook)
Recommended Posts