2017-04-22
Since Python2 is installed by default on the MAC, This time I introduced Python3.
■ Python3 version: 3.6.0 ■ Anaconda3 version: 4.3.1
■ OS X Yosemite 10.10.5
[wikipedia](https://ja.wikipedia.org/wiki/Homebrew_%28%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8% According to E7% AE% A1% E7% 90% 86% E3% 82% B7% E3% 82% B9% E3% 83% 86% E3% 83% A0% 29) Deploying software on the Mac OS X operating system It seems to be one of the package management systems that simplifies.
bash
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
It's a Python package management system, like Gem in Ruby. According to the Reference URL It seems that pip is installed by default from Python 2.7.9 or later and Python 3.4 or later. Before I knew this story, I struggled to introduce it with the following command.
■ Install pip
bash
$ curl -kL https://bootstrap.pypa.io/get-pip.py | sudo python
■ pip's own update command
bash
$ pip install -U pip
pyenv manages the python environment and It seems that you can create a python environment that is different from the standard environment.
(1) Install with homebrew
bash
$ brew install pyenv
$ brew install pyenv-virtualenv
(2) Add settings to .bash_profile (.bashrc)
bash
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
(3) Reread
bash
$ source .bash_profile
■ Check the installable version of Anaconda
bash
$ pyenv install -l
■ Anaconda installation Anaconda is provided by Continuum Analytics and is often used for science and technology, mathematics, engineering, data analysis, etc. in addition to Python itself. This is a package that allows you to install Python packages (400 or more as of February 2016) in a batch. It is widely used by Python developers because it allows for efficient and tedious setup tasks. Anaconda can also be used for commercial purposes. It seems that it is.
・ For Python3 series
bash
$ pyenv install anaconda3-X.X.X
・ For Python2 series
bash
$ pyenv install anaconda2-X.X.X
■ Check the list of installable versions
bash
$ pyenv install -l
■ Installation of Python alone
bash
$ pyenv install 3.6.0
■ pyenv Check the current version
bash
$ pyenv version
■ Check the list of installed versions
bash
$ pyenv versions
■ Setting the version to be used as a whole
bash
$ pyenv global 3.X.X
■ Setting the version to be used only under a specific directory
bash
$ cd PROJECT_DIR
$ pyenv local 3.X.XX
$ pyenv version
Python 2.7.11
$ cd ..
$ pyenv version
Python 3.5.1
(1) Switch the Anaconda environment to global
bash
$ pyenv global anaconda3-4.3.1
(2) Create a virtual environment with conda
bash
$ conda create --name py3.6.0 python=3.6.0
(3) Move to the working folder and execute pyenv local
bash
$ cd [Working folder]
$ pyenv local anaconda3-4.3.1/envs/py3.6.0
(4) Return global to system for the time being (optional)
bash
$ pyenv global system
(5) Activate and switch the environment
$ source $PYENV_ROOT/versions/anaconda3-4.3.1/bin/activate py3.6.0
(6) Check the version of python and Anaconda
bash
$ python -V
Python 3.6.0 :: Anaconda 4.3.1 (x86_64)
(7) Deactivate the environment with deactivate
bash
$ source $PYENV_ROOT/versions/anaconda3-4.3.1/bin/deactivate py3.6.0
(8) To switch the environment again, enter the working folder and activate.
bash
$ cd [Working folder]
$ source $PYENV_ROOT/versions/anaconda3-4.3.1/bin/activate py3.6.0
Recommended Posts