Until a Python inexperienced engineer builds a TensorFlow execution environment + comfortable coding environment on Mac

This is a good record for a Python inexperienced person to prepare the execution environment and comfortable coding environment of TensorFlow, which is a machine learning library published by Google. I also wanted to code Python itself comfortably, so I will try to build an environment where TensorFlow's MNIST demo can be executed with one click on Mac with Python 3.5.2 + PyCharm, which is the latest version at the time of writing this article.

Homebrew installation

First install the package management tool Homebrew

console


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

Even if it is already installed, it is recommended to update it just in case.

console


$ brew update

console


$ xcode-select --install

Install pyenv-virtualenv

Python is installed on the Mac from the beginning, but the version is 2.x series, and because of the SIP introduced from El Capitan, it is inflexible. I think it's a good idea to put the latest version of Python from pyenv and then use pyenv-virtualenv to isolate the environment.

Please install the tool from the following command

console


$ brew install pyenv-virtualenv

Install the latest version of Python

First, install the latest version of Python (here 3.5.2 is installed) Type pyenv install -l to see a list of installs

console


$ pyenv install 3.5.2
$ pyenv rehash

If you get an error with pyenv install, installing the Xcode command line tool may help (second time)

console


$ xcode-select --install

Create an environment for TensorFlow for Python 3.5.2.

In order to make the execution environment of TensorFlow independent, create an environment with a name based on the installed Python 3.5.2. By doing this, you can reduce errors due to conflicts between plugins and feel free to try different versions, making it closer to a virtual environment.

The "TensorFlow" part below is the name of the environment, so change it accordingly.

console


$ pyenv virtualenv 3.5.2 TensorFlow
$ pyenv rehash

Switch to the created TensorFlow environment

Use pyenv global to change to the created TensorFlow environment

console


$ pyenv global TensorFlow

Then hit the python command and it should change to 3.5.2.

console


$ python -V
Python 3.5.2

If the python command does not change the reference even though it is switched properly in pyenv as shown below,

console


$ pyenv version
TensorFlow (set by /Users/hogehoge/.pyenv/version)
$ python -V
Python 2.7.10

Try adding settings around here (maybe just the third line)

console


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

Also, after installing TensorFlow, you can restore the environment with the following if necessary

console


$ pyenv global system

Since the environment is specified by PyCharm described later, the python command does not necessarily have to be in the TensorFlow environment. Of course it is necessary when executing from the python command.

pip installation

Next, install pip, a plugin management tool for Python. If you have the latest Python installed, it seems to be included from the beginning, but just in case.

console


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

Install TensorFlow

At this point, we will finally move on to installing TensorFlow.

console


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

Since the installation URL of TensorFlow seems to specify the version, please check the latest version from Official. Here, v0.9 is specified.

Install PyCharm

And to build a comfortable Python coding environment, download PyCharm, an IDE developed by JetBrain Nemousu, from the following. https://www.jetbrains.com/pycharm/download/

Complements and breakpoints work perfectly, and Community Edition can be used for free. Great!

Create a project in PyCharm & apply project settings to TensorFlow environment

After starting PyCharm, create a project appropriately. At that time, specify "3.5.2 virtualenv at ~ / .pyenv / versions / TensorFlow" from the Interpreter pull-down on the Create Project dialog.

If you want to change the execution environment later, you can also change it from the pull-down menu of Preferences-> Project: PROJECT_NAME-> Project Interpreter.

Run TensorFlow's MNIST demo

The implementation of the MNIST demo of TensorFlow itself is sourced from the Official Tutorial and other commentary articles. Place the data (round throw) It was easy to just move it for the time being, so I followed the procedure on the ↓ site. http://www.trifields.jp/try-tutorial-mnist-for-ml-beginners-of-tensorflow-1713

Once the source and data are ready, click Run and you should see the result on the console at the bottom of the screen.

end

I don't think there are any people who are already using Python, but if you are a person like me who is new to Python because you want to run TensorFlow, you may stumble in various ways, so it flows as a memorandum. I summarized.

I referred to this article for the installation procedure http://qiita.com/hatapu/items/054dbab03607c47cb84f

Recommended Posts

Until a Python inexperienced engineer builds a TensorFlow execution environment + comfortable coding environment on Mac
Building a Python environment on Mac
Create a python environment on your Mac
Simply build a Python 3 execution environment on Windows
Build a Python environment on Mac (Mountain Lion)
Build a Python development environment on your Mac
Create a Python execution environment on IBM i
Build a machine learning Python environment on Mac OS
Create a comfortable Python 3 (Anaconda) development environment on windows
Build a Python development environment on Mac OS X
Build a Python environment on your Mac using pyenv
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
Building a Python environment on a Mac and using Jupyter lab
Build a python data analysis environment on Mac (El Capitan)
Create a virtual environment for python on mac [Very easy]
Until building a Python development environment using pyenv on Ubuntu 20.04
Building a Python environment on Ubuntu
Python environment construction memo on Mac
Create a python environment on centos
Environment construction of python3.8 on mac
Python3 TensorFlow for Mac environment construction
Build a python3 environment on CentOS7
Build a Python environment on your Mac with Anaconda and PyCharm
[Mac] Create a Python3 execution environment from the fully initialized state
Things to watch out for when creating a Python environment on a Mac
Build a python environment on MacOS (Catallina)
[Mac] Building a virtual environment for Python
Creating a python virtual environment on Windows
I installed Kivy on a Mac environment
Build Python environment with Anaconda on Mac
[Just a note] Until Keras + TensorFlow works on Mac OS X Sierra
I built a TensorFlow environment on windows10
Build a Python + OpenCV environment on Cloud9
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
Think about building a Python 3 environment in a Mac environment
[Venv] Create a python virtual environment on Ubuntu
Set up a Python development environment on Marvericks
Building a Python environment on a Sakura VPS server
Create a Python virtual development environment on Windows
Build a Python development environment on Raspberry Pi
Build a python execution environment with VS Code
python on mac
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
Steps to quickly create a deep learning environment on Mac with TensorFlow and OpenCV
Until you create a machine learning environment with Python on Windows 7 and run it
Build a Django development environment using pyenv-virtualenv on Mac
Install Python venv --VSCode --GitHub integration environment on Mac
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Build a local development environment for Laravel6.X on Mac
Notes on creating a python development environment on macOS Catalina
Until drawing a 3D graph in Python on windows10
Building a TensorFlow environment that uses GPU on Windows 10
I made a Python3 environment on Ubuntu with direnv.
Build a GVim-based Python development environment on Windows 10 (1) Installation
How to build a Django (python) environment on docker
Procedure for building a CDK environment on Windows (Python)
How to build a development environment for TensorFlow (1.0.0) (Mac)
Build a Python development environment using pyenv on MacOS
Building a Python environment for programming beginners (Mac OS)
Create a decent shell and python environment on Windows