Machine learning environment settings based on Python 3 on Mac (coexistence with Python 2)

Setting environment

Mac : OS X Yosemite(10.10.1)

Installation procedure

Homebrew installation

A very useful package management tool for Mac Homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install pyenv

Python version control tool pyenv

#Install pyenv
brew install pyenv

Next, set the PATH. Add the following settings to .zshrc and .bashrc.

#Setting environment variables
export PATH="$PYENV_ROOT/bin:$PATH"
export PYENV_ROOT="$HOME/.pyenv"

eval "$(pyenv init -)"

If you are using fish shell, add the following line instead of the last line in ↑ (~ / .config / fish / config.fish)

# pyenv
status --is-interactive; and . (pyenv init -| psub)

Installation of Anaconda

What is Anaconda?

Anaconda is a free distribution of various packages for building a Python numerical calculation environment.
By installing, NumPy, SciPy, matplotlib, of course,
Machine learning library scikit-You can install packages such as learn.

You can check the version of Python that can be installed with the following command

#View a list of installable Python
pyenv install -l

Screen Shot 2014-11-25 at 6.23.11 PM.png

Select the latest Anaconda (anaconda-3-2.1.0) from the list and select [as of November 25, 2014] Install Anaconda with the following command.

The default of Anaconda is Python3 series.

#Installation of Anaconda
pyenv install anaconda3-2.1.0

After installation, type the following command

pyenv rehash

After restarting the terminal (just in case)

#List of available Python
pyenv versions
(output)
* system
anaconda3-2.1.0 (set by /Users/yourname/.pyenv/version)

If, anaconda is installed normally.

Next, set the Python to use

#Python settings to use
pyenv global anaconda3-2.1.0
(output)
/Users/yourname/.pyenv/versions/anaconda3-2.1.0/bin/python

#Check the current Python version
pyenv version
(output)
anaconda3-2.1.0 (set by /Users/yourname/.pyenv/version)

#Confirmation of python reference source
which python
(output)
/Users/yourname/.pyenv/versions/anaconda3-2.1.0/bin/python

Once the settings are complete,

conda update conda

Let's update Anaconda itself

This completes the installation of Anaconda on Python 3 series.

Installation of Anaconda on Python 2 series

conda create -n py27 python=2.7 anaconda

Then you can install python2.7 Anaconda with the name py27 (py27 part is any name)

If you want to use this environment

source ~/.pyenv/versions/anaconda3-2.1.0/bin/activate py27

Then you can use it.

It is troublesome to type this long line every time, so it is convenient to set the following in the terminal configuration file.

alias py2='source ~/.pyenv/versions/anaconda3-2.1.0/bin/activate py27'
alias py3='source ~/.pyenv/versions/anaconda3-2.1.0/bin/deactivate'

Operation check

If you check the Python version in a normal terminal state, Screen Shot 2014-11-25 at 7.10.14 PM.png And Python3 series

Next, when I check the version of Python after activating the environment of python2.7, Screen Shot 2014-11-25 at 7.12.50 PM.png It is properly Python 2 series

Installation of OpenCV (Python2 series)

After making the environment of python2 system,

conda install opencv

As in the file or on ipython

import cv2

Then you will be able to use OpenCV with Python2 system.

Convenient plugin

yyuu/pyenv-pip-rehash

pyenv rehash

It automates the mysterious magic

# pyenv-pip-install rehash
git clone https://github.com/yyuu/pyenv-pip-rehash.git ~/.pyenv/plugins/pyenv-pip-rehash

reference

Building a Python machine learning environment on Mac (May 2014 version)

How to install 2 Anacondas (Python 2.7 and 3.4) on Mac OS 10.9

Introduction of Python numerical calculation environment Anaconda

Postscript

When putting in usr / local

#Setting environment variables
export PYENV_ROOT="/usr/local/opt/pyenv"
#pyenv code completion
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi

Recommended Posts

Machine learning environment settings based on Python 3 on Mac (coexistence with Python 2)
Build a machine learning Python environment on Mac OS
Build Python environment with Anaconda on Mac
Build AI / machine learning environment with Python
Build a Python machine learning environment with a container
[Definitive Edition] Building an environment for learning "machine learning" using Python on Mac
Machine learning with Python! Preparation
Beginning with Python machine learning
Build a machine learning application development environment with Python
Build a python machine learning study environment on macOS sierra
Build a machine learning environment on mac (pyenv, deeplearning, opencv)
Machine learning with python (1) Overall classification
Create a Python environment on Mac (2017/4)
Python environment construction memo on Mac
Until you create a machine learning environment with Python on Windows 7 and run it
"Scraping & machine learning with Python" Learning memo
I tried to build an environment for machine learning with Python (Mac OS X)
Building a Windows 7 environment for getting started with machine learning with Python
Python & Machine Learning Study Memo: Environment Preparation
[Python] Building an environment with Anaconda [Mac]
Competitive programming with python Local environment settings
Notes on PyQ machine learning python grammar
Amplify images for machine learning with python
Machine learning with python (2) Simple regression analysis
Create a python environment on your Mac
Creating amateur python environment settings (for MAC)
Follow active applications on Mac with Python
[Shakyo] Encounter with Python for machine learning
Python and machine learning environment construction (macOS)
Machine learning with Pytorch on Google Colab
python environment settings
python on mac
[Definitive Edition] Building an environment for learning "machine learning" using Python on Windows
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
[Python] Easy introduction to machine learning with python (SVM)
Machine learning starting with Python Personal memorandum Part2
Build python environment with pyenv on EC2 (ubuntu)
Machine learning starting with Python Personal memorandum Part1
Build a python environment with ansible on centos6
Beginning with Selenium
Beginning with PyTorch
Beginning with Python machine learning
[Python] Collect images with Icrawler for machine learning [1000 images]
Build a Python development environment on your Mac
Try working with Mongo in Python on Mac
Looking back on learning with Azure Machine Learning Studio
Learning Python with ChemTHEATER 03
"Object-oriented" learning with python
Learning Python with ChemTHEATER 05-1
Install Python 3 on Mac
Learning Python with ChemTHEATER 02
Learning Python with ChemTHEATER 01
Python environment with docker-compose
Install Python 3.4 on Mac
Mac environment construction Python
Virtual environment with Python 3.6
Install Python3 on Mac and build environment [Definitive Edition]
Build an interactive environment for machine learning in Python
Install Python venv --VSCode --GitHub integration environment on Mac
Run a machine learning pipeline with Cloud Dataflow (Python)
Install selenium on Mac and try it with python
Summary of python environment settings for myself [mac] [ubuntu]
I made a Python3 environment on Ubuntu with direnv.