It seems to be difficult for beginners to operate vim etc. when doing, so it is a procedure memo that makes it easy to operate on a notebook called jupyter. (* Although you can operate the terminal on the way!)
** jupyter image **
Docker image that can use TensorFlow with Jupyter --Memomemo
The method using docker is the quickest, but the macbook air that I always use is various and it is not good to use docker for mac, so I installed it normally ... The background is
Below is a simple flow
There is a procedure to do pyenv-virtualenv to make pyenv convenient, but I will omit it because there is no point in asking for it.
Instead of using system python common to all users, install env-based pyenv. (Recently, it is common to use env system to isolate the environment for both ruby and node).
Now you can create different versions of the python environment for running Tensorflow without affecting anything else.
Since I always use multiple ** env systems, I install anyenv that can manage them all at once, and install pyenv from there (I like this. You can put pyenv directly without any problem). The reason for doing this is that zshrc (or bashrc) gets dirty with a lot of env settings ...
Clone the repository by entering the following command
git clone https://github.com/riywo/anyenv ~/.anyenv
After that, add the following settings to bashrc etc. according to your environment so that anyenv is loaded when the shell starts.
.bashrc
if [ -d $HOME/.anyenv ] ; then
export PATH="$HOME/.anyenv/bin:$PATH"
eval "$(anyenv init -)"
In my dotfiles I set it like this https://github.com/kegamin/prezto/blob/master/runcoms/zshrc#L141-L143
After entering the settings, restart and reload the shell with ʻexec $ SHELL -l etc. to use ʻanyenv
. After that, execute ʻanyenv version`, and if you can execute it like the following, it's OK
❯ anyenv version
ndenv: v5.6.0 (set by /Users/user/.anyenv/envs/ndenv/version)
plenv: system (set by /Users/user/.anyenv/envs/plenv/version)
pyenv: 3.5.1 (set by /Users/user/.anyenv/envs/pyenv/version)
rbenv: 2.3.0 (set by /Users/user/.anyenv/envs/rbenv/version)
#Install pyenv
❯ anyenv install pyenv
#List of python versions that can be installed
❯ pyenv install -l
Available versions:
(Omission)
3.5.0
3.5-dev
3.5.1 #->Put this this time
3.6.0a1
3.6-dev
(Abbreviation)
❯ pyenv install 3.5.1
#Standardize installed python
❯ pyenv global 3.5.1
#Check version(*The python version currently in use)
❯ pyenv versions
system
* 3.5.1 (set by /Users/user/.anyenv/envs/pyenv/version)
# install
❯ pip install jupyter matplotlib
#Start-up
❯ jupyter notebook
[I 13:47:54.142 NotebookApp] Serving notebooks from local directory: /Users/user/Dropbox/notebook
[I 13:47:54.142 NotebookApp] 0 active kernels
[I 13:47:54.142 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/
[I 13:47:54.142 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
From Download and Setup, check the URL of the current latest version of tensorflow and install it.
Regarding the Mac version, there are the following two types, but if you are not sure, it is better to select CPU only (If you have a mac with GPU, it is better to select GPU enabled, it will process faster using GPU However, I will omit it this time, but more things will be installed).
Mac OS X, CPU only, Python 3.4 or 3.5: Mac OS X, GPU enabled, Python 3.4 or 3.5:
# 2016/09/10 Currently 0.10 is the latest Ver
$ pip install -U https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.10.0-py3-none-any.whl
#Create a directory to save the created tensorflow data (any location))
❯ mkdir tensorflow
❯ ls
tensorflow
#Specify the created directory and start jupyter
❯ jupyter notebook tensorflow
[I 14:38:42.255 NotebookApp] Serving notebooks from local directory: /Volumes/usb128/jupyter/tensorflow
[I 14:38:42.255 NotebookApp] 0 active kernels
[I 14:38:42.255 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/
[I 14:38:42.255 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
After executing jupyter notebook
, when you start http: // localhost: 8080
with a browser, the screen below is displayed.
** You did it! ** **
Now, let's actually execute tensorflow. As shown in the image below, press New on the right and select python 3
in it.
Then, the input screen will appear as shown below, so try inserting the source code.
The following source code is input for each, but if you press SHIFT + Enter
on the source code after inputting, the execution result will be output immediately below (it may take some time).
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
import tensorflow as tf
a = tf.constant(10)
b = tf.constant(20)
print(sess.run(a + b))
jupyter is variously sophisticated and fun, but this time I will omit the operation method etc.
enjoy! TensorFlow!
pyenv-virtualenv + TensorFlow environment setting memorandum [addition / correction] --Qiita
Recommended Posts