I read TensorFlow --MNIST For ML Beginners to learn by playing with Jupyter Notebook, and I wanted an environment where I can run Tensorflow using Jupyter Notebook even on windows. I tried to build it.
Bash on Ubuntu on Windows includes python by default, but Anaconda I wanted to use it, so I installed pyenv.
$ sudo aptitude install git
$ git clone https://github.com/yyuu/pyenv ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc
$ source ~/.bashrc
After installing pyenv,
$ pyenv install --list
And look for the latest version of Anaconda. 3-4.2.0 was the latest at the time of writing this article So I installed 3-4.2.0 and made it the default setting.
$ pyenv install anaconda3-4.2.0
$ pyenv global anaconda3-4.2.0
$ pyenv rehash
Refer to Reference article [2] to prepare the environment for using the X11 GUI application.
Download and install the following application on windows.
After that, in Bash on Ubuntu on Windows, enter X11 with the following command and write the DISPLAY setting in .bashrc.
$ sudo aptitude install x11-apps
$ echo 'export DISPLAY=localhost:0.0' >> ~/.bashrc
$ source ~/.bashrc
Finally, display xclock to check the operation.
$ xclock
Matplotlib is required to display the graph with jupyter, so prepare for it.
sudo aptitude install libqtgui4
conda install matplotlib
Also, numpy used in the following code is mkl compatible and an error will occur, so Replace with nomkl's.
conda install nomkl
conda update --all
If you execute the following code in this state, confirm that an image of the sin curve is created.
sin_plot.py
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
plt.savefig('sin_curve.png')
In Bash on Ubuntu on Windows, an error occurs around libzmq3, so install libzmq3 corresponding to it.
$ sudo add-apt-repository ppa:aseering/wsl
$ sudo aptitude update
$ sudo aptitude install libzmq3
$ conda install -c jzuhone zeromq=4.1.dev0
$ conda install jupyter
Finally, execute the following command to start Jupyter and http: // localhost: 8888 / You will be able to connect with and run python.
jupyter notebook --no-browser
I want to display the matplotlib graph inline in the jupyter notebook In that case, you can display it in jupyter's notebook by writing as follows.
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
Reference article [1] with reference to anaconda Put Tensorflow in the environment of.
conda install -c conda-forge tensorflow
Finally, on Jupyter's Notebook, https://www.tensorflow.org/get_started/ If you paste the code in and execute it, the result will be returned, so You can see that Tensorflow is installed.
I referred to the following article. Thank you very much.
Recommended Posts