Python3 TensorFlow for Mac environment construction

Premise

About this tutorial

Learning TensorFlow from scratch requires various knowledge and expensive computers, but in this tutorial, we will remove those assumptions and build a TensorFlow environment based on the feeling of "** I will try to move it for the time being **". I will do it.

environment

If you want to run TensorFlow on python3.7 or above, the following article will be helpful. Reference: A story about building a Tensorflow environment with MacOS Mojave & Python3.7

If you want to run it on macOS Mojave, the following article will be helpful. Reference: Enable python3 system using pyenv on macOS Mojave

Target audience

--Those who want to start TensorFlow --For those who want to run TensorFlow for the time being --Those who want to build an environment with the minimum configuration

table of contents

--1. Install Xcode Command Line Tools ―― 2. Install Homebrew --3. Installation of pyenv-virtualenv ―― 4. Build a Python environment for TensorFlow --5. Install pip ―― 6. Installation of TensorFlow

Build a TensorFlow development environment

1. Install Xcode Command Line Tools

What is Command Line Tools?

Command Line Tools is part of Apple's integrated development environment for MacOS / MacOSX. It includes the GCC compiler, etc. required to install UNIX-based applications. If you have an Apple ID, you can also download it at Apple Developer. ** Please [Get] Xcode from the App Store (https://itunes.apple.com/jp/app/xcode/id497799835?mt=12) before installing Command Line Tools. ** **

This is a prerequisite for Homebrew to be installed later. Install Xcode Command Line tools.

terminal


$xcode-select --install

If you are asked to grant a license, please accept the license agreement.

terminal


$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

2. Install Homebrew

What is HomeBrew?

HomeBrew is a package manager provided for MacOS / MacOSX. You can manage the software from the command line. Generally, when installing software, you need to manually obtain the software executable file or manually build the source code, and HomeBrew does a series of these tasks automatically.

Homebrew Copy and execute the following command described on the official website.

terminal


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

If the output is as below, Homebrew installation is complete.

terminal


$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
...
...
==> Installation successful!
==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics.html
==> Next steps:
- Run `brew help` to get started
- Further documentation: 
    https://docs.brew.sh

3. Install pyenv-virtualenv

What are pyenv and pyenv-virtualenv?

pyenv is a python version control system. You can switch the Python version. pyenv-virtualenv is a Pyenv plugin for managing your Python environment.

Install pyenv with Homebrew.

terminal


$ brew install pyenv

Install pyenv-virtualenv with Homebrew.

terminal


$ brew install pyenv-virtualenv

Display and check the Python version list.

terminal


$ pyenv install -l

Install Python 3.6.0 and refresh Shims.

terminal


$ pyenv install 3.6.0
...
...
$ pyenv rehash

4. Build a Python environment for TensorFlow

Create a Python environment for TensorFlow.

terminal


$ pyenv virtualenv 3.6.0 TensorFlow
$ pyenv rehash

Specify the Python environment created for TensorFlow.

terminal


$ pyenv global TensorFlow

Check the Python environment you specified for TensorFlow.

terminal


$ python --version
Python 3.6.0

5. Install pip

What is pip

pip (Pip javax Packages) is a Python package management system. If you want to use third party libraries with python, you can manage those packages with pip.

Install and update the Python plugin management tool (pip).

terminal


$ sudo easy_install pip
$ sudo easy_install --upgrade six
$ sudo pip install --upgrade pip

6. Install TensorFlow

Install TensorFlow with pip.

terminal


$ pip3 install --upgrade tensorflow

Check the operation of TensorFlow.

terminal


$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Hello, TensorFlow!

If an error is output as shown below, please also refer to the link below.

terminal


this TensorFlow binary was not compiled to use: AVX2 FMA

Reference: (Qiita) "this TensorFlow binary was not compiled to use: AVX2 FMA" error on macOS

Exit with exit ().

terminal


>>> exit()

Next time I will play with TensorFlow.

Postscript

2017/8/21 Added the items to be installed by pyenv.

Recommended Posts

Python3 TensorFlow for Mac environment construction
Mac environment construction Python
Python3 environment construction (for beginners)
Python environment construction and TensorFlow
Ansible environment construction For Mac
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
Python environment construction
I checked Mac Python environment construction
Environment construction (python)
Python environment construction memo on Mac
Python environment construction (pyenv, anaconda, tensorflow)
python environment construction
Environment construction of python3.8 on mac
Python environment construction
python environment construction
Python project environment construction procedure (for windows)
Creating amateur python environment settings (for MAC)
[Mac] Building a virtual environment for Python
python windows environment construction
homebrew python environment construction
Anaconda-4.2.0-python3 environment construction (Mac)
Python development environment construction
python2.7 development environment construction
Pyxel environment construction (Mac)
Python environment construction @ Win7
Python environment for projects
Python explosive environment construction starting from zero (Mac)
Building an environment for executing Python scripts (for mac)
[Ubuntu 18.04] Tensorflow 2.0.0-GPU environment construction
Python + Anaconda + Pycharm environment construction
Set Up for Mac (Python)
CI environment construction ~ Python edition ~
Anaconda3 python environment construction procedure
Python environment construction under Windows7 environment
[MEMO] [Development environment construction] Python
[For organizing] Python development environment
Ubuntu14.04 + GPU + TensorFlow environment construction
[Tensorflow] Tensorflow environment construction on Windows 10
Environment construction of python2 & 3 (OSX)
Summary of python environment settings for myself [mac] [ubuntu]
[Python] Django environment construction (pyenv + pyenv-virtualenv + Anaconda) for macOS
How to build a development environment for TensorFlow (1.0.0) (Mac)
Building a Python environment for programming beginners (Mac OS)
Python environment construction on Mac (pyenv, virtualenv, anaconda, ipython notebook)
Building a Python environment on Mac
Environment construction of python and opencv
Mac + Eclipse (PyDev) + Django environment construction
Python environment construction memo on Windows 10
Get started with Python! ~ ① Environment construction ~
Anaconda python environment construction on Windows 10
Python + Unity Reinforcement learning environment construction
Building a python environment for artificial intelligence (Chainer / TensorFlow / CSLAIER)
Anaconda environment construction on Mac (2018 version)
[For beginners] Django -Development environment construction-
[Python3] Development environment construction << Windows edition >>
Python development environment options for May 2020
install tensorflow in anaconda + python3.5 environment
Python development environment construction on macOS
Python environment construction (pyenv + poetry + pipx)
Emacs settings for Python development environment
Python3 environment construction with pyenv-virtualenv (CentOS 7.3)