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).
The installation procedure is omitted. If it is already installed, only update it.
$ brew update
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
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 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
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.
Install pip3, a Python3 package management tool.
$ sudo easy_install pip
$ sudo easy_install --upgrade six
$ pip install --upgrade pip
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. ..
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
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
If you want to delete the virtual environment, execute the following command.
$ sudo pyenv uninstall -f {Virtual environment name}
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.
Change PyCharm settings.
∵ Because PEP8 (Python coding standard) stipulates up to 79 characters per line
Preferences… Editor > Code Style Default Options Right margin (columns):120→79
∵ I don't want to include spaces in blank lines
Preferences… Editor > General > Appearance Show whitespaces:OFF→ON Turn off except Trailing
Preferences… Editor > General > Code Completion Code Completion Case sensitive completion: First letter→None
Please put this as you like.
Preferences… Plugins Install JetBrains plugin… Search for "vim" and install IdeaVim
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.
This completes the TensorFlow development environment construction. Enjoy a wonderful TensorFlow life!