Python3 TensorFlow environment construction (Mac and pyenv virtualenv)

environment

Mac OS X El Capitan 10.11.3 MacBook Pro (Retina, 13-inch Early 2015)

Preparation

HomeBrew is required, so install it if you don't have it

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

pyenv You can manage multiple versions of the Python environment and switch between them with commands.

Installation

$ brew install pyenv

Add the following to ~ / .profile

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"

Check the current Python installation status (only the system is displayed before the environment is built)

$ pyenv versions
* system (set by /Users/yusuke/.pyenv/version)

List of installable Python versions (results only show where you think you need them)

$ pyenv install --list
  2.7.11
  ...
  3.5.1
  ...
  anaconda3-2.4.0
  ...

Install the latest Python 3

$ pyenv install 3.5.1

If you get an error like this

zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1

Install command line tools

$ xcode-select --install

Reread the settings

$ . .profile

Reinstall

$ pyenv install 3.5.1

It seems better to rehash after installation

$ pyenv rehash

If you check the installed environment, it should look like this

$ pyenv versions
* system (set by /Users/yusuke/.pyenv/version)
  3.5.1

Check by setting the default environment to 3.5.1.

$ pyenv global 3.5.1
$ pyenv versions
  system
* 3.5.1 (set by /Users/yusuke/.pyenv/version)

anaconda A distribution that allows you to install Python and the Numerical Library at the same time, I will not use it this time, but I will install it because it is convenient. For Python3 series, select anaconda3, the latest version is 2.4.0, so install with the following command

$ pyenv install anaconda3-2.4.0

Rehash after installation

$ pyenv rehash

If you check the installed environment, it should look like this

$ pyenv versions
  system
* 3.5.1 (set by /Users/yusuke/.pyenv/version)
  anaconda3-2.4.0

virtualenv I will not use it this time. Whereas pyenv has an environment for each version, virtualenv allows you to switch between environments by giving a name to the environment (even with the same version of Python, you can keep it with a different name like python35hoge, python35fuga).

pyenv-virtualenv With pyenv, it was managed for each version, but you can name the pyenv environment, manage it more finely, and switch.

Installation

$ brew install pyenv-virtualenv

This time I want to create a TensorFlow environment with Python 3.5.1, so let's name it `` `py351tensorflow```. Installation and confirmation are as follows.

$ pyenv version
3.5.1 (set by /Users/yusuke/.pyenv/version)
$ pyenv virtualenv 3.5.1 py351tensorflow
$ pyenv rehash
$ pyenv versions
  system
* 3.5.1 (set by /Users/yusuke/.pyenv/version)
  3.5.1/envs/py351tensorflow
  anaconda3-2.4.0
  py351tensorflow

TensorFlow A machine learning library that Google made open source in November 2015. A lot of detailed explanations will come out if you google, so I will omit it here.

Click here for official documentation https://www.tensorflow.org/versions/master/get_started/os_setup.html

Use the py351tensorflow environment installed with pyenv-virtualenv earlier

$ pyenv global py351tensorflow
$ pyenv version
py351tensorflow (set by /Users/yusuke/.pyenv/version)

Install version 0.6.0 for Python 3

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

Successful installation

Successfully installed numpy-1.10.4 protobuf-3.0.0a3 setuptools-19.6 six-1.10.0 tensorflow-0.6.0 wheel-0.26.0

Confirmed operation according to the official document

$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
I tensorflow/core/common_runtime/local_device.cc:40] Local device intra op parallelism threads: 4
I tensorflow/core/common_runtime/direct_session.cc:58] Direct session inter op parallelism threads: 4
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42
>>> quit() 

If this is the case, the installation is successful.

Recommended Posts

Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
Python environment construction and TensorFlow
Python environment construction (pyenv, anaconda, tensorflow)
Python3 TensorFlow for Mac environment construction
Python environment construction on Mac (pyenv, virtualenv, anaconda, ipython notebook)
Mac environment construction Python
python development environment -use of pyenv and virtualenv-
Python environment construction For Mac
Python virtual environment construction (2017 version) pyenv and pyenv-virtualenv and virtualenv and virtualenv wrapper and pyvenv and venv
Environment construction of python and opencv
I checked Mac Python environment construction
Python environment construction memo on Mac
Python environment construction (pyenv + poetry + pipx)
Environment construction of python3.8 on mac
Environment construction with pyenv and pyenv-virtualenv
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
Python environment construction
Environment construction (python)
python environment construction
Python --Environment construction
Python environment construction
python environment construction
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
Notes on building Python and pyenv on Mac
Python and machine learning environment construction (macOS)
Clean python environment with pythonz and virtualenv
Building a python environment with virtualenv and direnv
python windows environment construction
Python explosive environment construction starting from zero (Mac)
homebrew python environment construction
Pyenv + virtualenv on Mac
Anaconda-4.2.0-python3 environment construction (Mac)
Python development environment construction
Installation of Python3 and Flask [Environment construction summary]
Try to build python and anaconda environment on Mac (by pyenv, conda)
pyenv + fish environment construction
python2.7 development environment construction
Notes on setting pyenv and python environment using Homebrew on Mac OS Marvericks
[Django3] Environment construction and various settings summary [Python3]
Try using tensorflow ① Build python environment and introduce tensorflow
Python 3.x environment construction by Pyenv (CentOS, Ubuntu)
Remove old pyenv environment on Mac and update
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Pyxel environment construction (Mac)
Python environment construction @ Win7
Install Python3 on Mac and build environment [Definitive Edition]
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a Python environment on your Mac using pyenv
Build a python virtual environment with virtualenv and virtualenvwrapper
Environment construction with anyenv + pyenv (migrate from pyenv only (Mac))
[Python] Django environment construction (pyenv + pyenv-virtualenv + Anaconda) for macOS
Install Python environment on local PC (pyenv, venv on Mac)
[Ubuntu 18.04] Tensorflow 2.0.0-GPU environment construction
Python + Anaconda + Pycharm environment construction
Mechanism of pyenv and virtualenv
Manage python environment with virtualenv
Python environment construction (Windows10 + Emacs)
CI environment construction ~ Python edition ~
Anaconda3 python environment construction procedure
Python3 environment construction (for beginners)
NumPy and matplotlib environment construction