How to build a development environment for TensorFlow (1.0.0) (Mac)

Introduction

I will explain how to build a TensorFlow development environment from a state where there is no Python development environment at all. So, if you are already programming in Python, please read only the TensorFlow part. The target of this article is someone who is like "Python? Pee ... Tson? I don't know, but I want to use TensorFlow" (I was a while ago).

environment

Development environment construction

Homebrew installation / update

The installation procedure is omitted. If it is already installed, only update it.

$ brew update

Install pyenv-virtualenv

pyenv-virtualenv is a virtualization tool for Python environments. I will introduce it because I can build a Python environment for TensorFlow without polluting the real environment.

$ brew install pyenv-virtualenv

Add the following to ~ / .bash_profile and pass the path.

.bash_profile


export PYENV_ROOT="$HOME/.pyenv"
if [ -d "${PYENV_ROOT}" ]; then
  export PATH="$PATH:$HOME/.pyenv/bin"
  eval "$(pyenv init -)"
  eval "$(pyenv virtualenv-init -)"
fi

Installation of Python3 series

Install Python with Anaconda. Anaconda is a package that allows you to install Python and its main packages in bulk. Run the following command to check for the latest version of Anaconda. As of March 27, 2017, "anaconda 3-4.3.0" is the latest.

$ pyenv install -l
Available versions:
  …
  anaconda-1.4.0
  anaconda-1.5.0
  …
  anaconda3-4.3.0
  …

Install the latest version of Anaconda. It may take some time depending on the communication environment.

$ pyenv install anaconda3-4.3.0

If you get an error, try the following and then install Anaconda again.

$ xcode-select --install
$ pyenv rehash

After the Anaconda installation is complete, check if it is installed. All you need is "anaconda 3-4.3.0".

$ pyenv versions
* system (set by /Users/{username}/.pyenv/version)
  anaconda3-4.3.0

$ ls ~/.pyenv/versions/
anaconda3-4.3.0

Create virtual environment

Create a virtual environment with any name based on "anaconda3-4.3.0". Here, it is called "tensorFlow".

$ pyenv virtualenv anaconda3-4.3.0 tensorFlow
$ pyenv rehash

Check if the virtual environment has been created. All you need is "anaconda3-4.3.0 / envs / tensorFlow" and "tensorFlow". The difference between the two is still unknown. ..

$ pyenv versions
* system (set by /Users/{username}/.pyenv/version)
  anaconda3-4.3.0
  anaconda3-4.3.0/envs/tensorFlow
  tensorFlow

Switching virtual environment

Switch to the virtual environment you just created.

$ pyenv global tensorFlow

Check if the environment has changed. If "*" is added at the beginning of "tensorFlow", the environment has been switched. Also check the Python version. It seems to be 3.6.1 in anaconda3-4.3.0.

$ pyenv versions
  system
  anaconda3-4.3.0
  anaconda3-4.3.0/envs/tensorFlow
* tensorFlow (set by /Users/{username}/.pyenv/version)

$ python --version
Python 3.6.1 :: Continuum Analytics, Inc.

pip3 installation / update

Install pip3, a Python3 package management tool.

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

Package installation

matplotlib is a graph drawing library and is often used, so install it. Jupyter is simply a tool that runs Python interactively. It may not be necessary when using PyCharm, but it is convenient, so install it.

$ sudo pip3 install matplotlib
$ sudo pip3 install jupyter

Both should be included in Anaconda, but for some reason I can't use them unless I install them here. I think the package will be taken over. ..

Install TensorFlow

Refer to 5. of Official Site and install TensorFlow suitable for your environment with pip3. The MacBook I'm using doesn't have a GPU, so I chose CPU only.

# Mac OS X, CPU only, Python 3.n
$ pip3 install --upgrade tensorflow

Reswitching virtual environment

As we will see later, the Python environment is specified elsewhere, so you can restore the virtual environment specified in the terminal.

$ pyenv global system

Uninstall virtual environment

If you want to delete the virtual environment, execute the following command.

$ sudo pyenv uninstall -f {Virtual environment name}

Install PyCharm

Install PyCharm, the Python IDE. Click the [DOWNLOAD] button of Community (free version) from Official Site to download the installer. It may take some time depending on the communication environment. When the download is complete, double-click to run and install. After installation, start it. Since this is a new installation, select "Do not import settings" and click the [OK] button. Initial Configuration can be Skipped.

PyCharm settings

Change PyCharm settings.

A warning will be issued if 80 characters or more are written on one line.

∵ Because PEP8 (Python coding standard) stipulates up to 79 characters per line

Preferences… Editor > Code Style Default Options Right margin (columns):120→79

Visualize blank line space

∵ I don't want to include spaces in blank lines

Preferences… Editor > General > Appearance Show whitespaces:OFF→ON Turn off except Trailing

Insensitive when completing

Preferences… Editor > General > Code Completion Code Completion Case sensitive completion: First letter→None

Introducing the Vim plugin

Please put this as you like.

Preferences… Plugins Install JetBrains plugin… Search for "vim" and install IdeaVim

PyCharm project creation

Create New Project --Location: The path of the project. The last part will be the project name, so change it to something like "tensorFlowTest". --Interpreter: The Python environment to apply. Select the created virtual environment "~ / .pyenv / versions / tensorFlow / bin / python" and it's OK. The tip displayed after that can be closed.

in conclusion

This completes the TensorFlow development environment construction. Enjoy a wonderful TensorFlow life!

Reference link

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

Recommended Posts

How to build a development environment for TensorFlow (1.0.0) (Mac)
[Note] How to create a Mac development environment
Build a local development environment for Laravel6.X on Mac
How to build a python2.7 series development environment with Vagrant
Build a Python development environment on your Mac
Build a Kubernetes environment for development on Ubuntu
[Note] How to create a Ruby development environment
[TF] How to build Tensorflow in Proxy environment
Build a mruby development environment for ESP32 (Linux)
How to force build TensorFlow 2.3.0 for CUDA11 + cuDNN8
I tried to build a Mac Python development environment with pythonz + direnv
Build a Django development environment using pyenv-virtualenv on Mac
How to build a Django (python) environment on docker
I want to easily build a model-based development environment
Build a Python development environment on Mac OS X
How to build a Python environment on amazon linux 2
I want to create a nice Python development environment for my new Mac
How to build an environment for using multiple versions of Python on Mac
Python3 TensorFlow for Mac environment construction
How to build a new python virtual environment on Ubuntu
[Memo] Build a development environment for Django + Nuxt.js with Docker
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
How to build a LAMP environment using Vagrant and VirtulBox Note
Easily build a development environment with Laragon
Build a local development environment for Lambda + Python using Serverless Framework
Build a Tensorflow environment with Raspberry Pi [2020]
I want to build a Python environment
[Mac] Building a virtual environment for Python
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
Spigot (Paper) Introduction to how to make a plug-in for 2020 # 01 (Environment construction)
How to use tensorflow under docker environment
Prepare the development environment for keyhac for Mac
Building a Python development environment for AI development
Creating a development environment for machine learning
[DynamoDB] [Docker] Build a development environment for DynamoDB and Django with docker-compose
Anyone can understand how to build an initial environment for Python on Mac September 2016 (pyenv + virutalenv)
Things to watch out for when creating a Python environment on a Mac
After buying a new Mac, use pyenv + poetry to build a Python environment.
[Development environment] How to create a data set close to the production DB
Summary of how to build a LAMP + Wordpress environment with Sakura VPS
Build a C language development environment with a container
How to share a virtual environment [About requirements.txt]
For beginners to build an Anaconda environment. (Memo)
How to create a Python virtual environment (venv)
[Latest] How to build Java environment on Ubuntu
Build a Python environment on Mac (Mountain Lion)
[Python] Build a Django development environment with Docker
I created a Dockerfile for Django's development environment
How to write a ShellScript Bash for statement
How to create a shortcut command for LINUX
How to set up a local development server
Build a Minecraft plugin development environment in Eclipse
How to build Java environment on Ubuntu (Linux)
[PyTorch] Sample ⑧ ~ How to build a complex model ~
Build a Python development environment on Raspberry Pi
Flutter in Docker-How to build and use a Flutter development environment inside a Docker container
How to run a Django application on a Docker container (development and production environment)
Build a TensorFlow development environment on Amazon EC2 with command copy and paste
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
How to set up a Python environment using pyenv