Build an environment for machine learning using Python on MacOSX

This is a memo for building a development environment for reading the following books.

Book: Scraping & Machine Learning Development Techniques with Python http://www.socym.co.jp/book/1079

ac15a1df2c2dca10a4c215f6096d8892.jpg

Homebrew installation

First of all, install the package manager "Homebrew" for Mac OS X. http://brew.sh/index_ja.html

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

On the way, enter the sudo password.

pyenv

Next, install the Python version manager "pyenv".

You can change the environment (installed packages) for each Python version.

$ brew install pyenv

Set environment variables.

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
$ echo 'eval "$(pyenv init -)"' >> ~/.profile
$ . ~/.profile

Check the versions and packages that can be installed using pyenv.

$ pyenv install --list

Install the latest Python 3.6.0 and anaconda 3-4.2.0.

$ pyenv install 3.6.0
$ pyenv install anaconda3-4.2.0

Check the installed version.

$ pyenv versions

Switch the version as follows. (Change global to local if you want to apply only to a specific directory)

(python3.6.Switch to 0)
$ pyenv global 3.6.0
$ pyenv rehash
$ python --version
Python 3.6.0
$ pyenv versions
  system
* 3.6.0 (set by /Users/hisashi/.pyenv/version)
  anaconda3-4.2.0

(anaconda3-4.2.Switch to 0)
$ pyenv global anaconda3-4.2.0
$ pyenv rehash
$ python --version
Python 3.5.2 :: Anaconda 4.2.0 (x86_64)
$ pyenv versions
  system
  3.6.0
* anaconda3-4.2.0 (set by /Users/hisashi/.pyenv/version)

Package management

Python package management is done with "pip". In addition, Anaconda package management is performed by "conda" and "pip".

editor

I think Atom is a good editor. https://atom.io

PhantomJS and Selenium

It is a setting of scraping via a browser (Chapter 2, Section 2). We will use "anaconda 3-4.2.0" which is often used in machine learning.

$ pyenv global anaconda3-4.2.0
$ pyenv rehash

The book introduces the environment construction with Ubuntu + docker, but with MacOSX you can build the environment as follows.

$ brew install phantomjs
$ pip install selenium
$ pip install beautifulsoup4

Install TensorFlow

I will continue to use "anaconda 3-4.2.0".

In the book, the following command is described, but an error occurs and it stops halfway.

$ pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py3-none-any.whl

You should add the "-I setuptools" option to avoid errors. http://datalove.hatenadiary.jp/entry/python/anaconda/install-tensorflow-into-anaconda-environment

$ pip install --upgrade -I setuptools https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py3-none-any.whl

Recommended Posts

Build an environment for machine learning using Python on MacOSX
Build an interactive environment for machine learning in Python
[Definitive Edition] Building an environment for learning "machine learning" using Python on Windows
[Definitive Edition] Building an environment for learning "machine learning" using Python on Mac
Build a machine learning Python environment on Mac OS
Memo for building a machine learning environment using Python
How to build an environment for using multiple versions of Python on Mac
Build a python machine learning study environment on macOS sierra
Build an environment for Blender built-in Python
An introduction to Python for machine learning
Build AI / machine learning environment with Python
I tried to build an environment for machine learning with Python (Mac OS X)
Build Python3.5 + matplotlib environment on Ubuntu 12 using Anaconda
Build a Python machine learning environment with a container
Build Python environment on Windows
Build python environment on windows
Build a machine learning environment
Build an OpenCV4 environment on Raspberry Pi using Poetry
Build a Python environment on your Mac using pyenv
Build a machine learning application development environment with Python
Build a Python development environment using pyenv on MacOS
Build a machine learning environment natively on Windows 10 (x64)
Rebuilding an environment for machine learning with Miniconda (Windows version)
Build a machine learning environment on mac (pyenv, deeplearning, opencv)
Build a machine learning environment using PyCharm on Ubuntu environment (TensorFlow will also be introduced!)
Build an Ubuntu python development environment on Google Cloud Platform
<For beginners> python library <For machine learning>
Machine learning environment settings based on Python 3 on Mac (coexistence with Python 2)
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
Build a python3 environment on CentOS7
Build a PyData environment for a machine learning study session (January 2017)
Build a python environment on CentOS 7.7 for your home server
[Python machine learning] Recommendation of using Spyder for beginners (as of August 2020)
How about Anaconda for building a machine learning environment in Python?
Build a local development environment for Lambda + Python using Serverless Framework
Building a Windows 7 environment for getting started with machine learning with Python
Try using virtualenv, which can build a virtual environment for Python
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
Build and try an OpenCV & Python environment in minutes using Docker
Building an HPC learning environment using Docker Compose (C, Python, Fortran)
Python & Machine Learning Study Memo: Environment Preparation
Notes for using OpenCV on Windows10 Python 3.8.3.
Python development environment for macOS using venv 2016
Python 2.7, 3.4, 3.5 extension module build environment on Windows
Notes on PyQ machine learning python grammar
Amplify images for machine learning with python
Build Python3 and OpenCV environment on Ubuntu 18.04
Build a python environment on MacOS (Catallina)
An introduction to OpenCV for machine learning
Why Python is chosen for machine learning
Build an LNPP environment on Amazon Linux 2
[Shakyo] Encounter with Python for machine learning
Build Python environment with Anaconda on Mac
[Python] When an amateur starts machine learning
[Python] Web application design for machine learning
Python and machine learning environment construction (macOS)
Create an OpenCV3 + python3 environment on OSX
Build a Python + OpenCV environment on Cloud9
Creating a development environment for machine learning
Building an environment for "Tello_Video" on Raspbian
Building an environment for "Tello_Video" on Windows