Build a python environment to learn the theory and implementation of deep learning

Recently, I started to touch python a little for studying machine learning. This time, I will organize about building a python environment on CentOS 7.

environment

1. Add the IUS Community Project repository

The python 3 series is not provided in the CentOS 7 repository, so you need to register the repository separately.

# yum install -y https://centos7.iuscommunity.org/ius-release.rpm

However, since it is a repository that is not normally used, it should be disabled and used only if you want to use it.

# vim /etc/yum.repos.d/ius.repo
[ius]
enabled=1
↓
enabled=0

2. Install the latest python

The latest provided by ius was 3.5.2, so I will use it this time.

# yum clean all
# yum install --enablerepo=ius -y python35u python35u-libs python35u-devel python35u-pip

However, as it is, the path is heading to python, which is included by default, so it points to system 2.

$ python --version
Python 2.7.5

The reason for this is that the alias is pasted as follows.

# ls -l /bin/python                                                            
lrwxrwxrwx 1 root root 7 December 17 17:56 /bin/python -> python2
# ls -l /bin/python2
lrwxrwxrwx 1 root root 9 December 17 17:56 /bin/python2 -> python2.7
# ls -l /bin/python3*                                                          
-rwxr-xr-x 2 root root 11304 June 28 2016/bin/python3.5
lrwxrwxrwx 1 root root 26 January 1 20:02 /bin/python3.5-config -> /usr/bin/python3.5m-config
-rwxr-xr-x 2 root root 11304 June 28 2016/bin/python3.5m
-rwxr-xr-x 1 root root 173 June 28 2016/bin/python3.5m-config
-rwxr-xr-x 1 root root 3398 June 28 2016/bin/python3.5m-x86_64-config

Note that it is NG to re-paste the symbolic link from python to 3 series. If you replace it, various things using python2 system will not work.

For example, yum can't be used. I get an error like this.

File "/usr/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^

So, when using the 3rd system, try using it as follows for the time being. (Usually, how should I use it? Is it better to use pyenv?)

# ln -s /bin/python3.5 /bin/python3
# python3 --version
Python 3.5.2

Since pip also has a pass to 2.7.

# ln -s /bin/pip3.5 /bin/pip3
# pip3 --version
pip 9.0.1 from /usr/lib/python3.5/site-packages (python 3.5)

3. Install the external libraries NumPy and Matplotlib

This time, for studying, I will use "NumPy" which provides a multidimensional array and "Matplotlib" which can draw graphs and visualize data.

The following packages are also required to import Matplotlib, so install them.

# yum install --enablerepo=ius -y python35u-tkinter

Then install NumPy and Matplotlib.

# pip3 install numpy matplotlib

The preparation is now complete. After that, if you write a script like this and run it, you can output a graph.

sample-graph.py


 1 #!/bin/python3
 2 import numpy as np
 3 import matplotlib.pyplot as plt
 4 
 5 x = np.arange(0,6,0.1)
 6 y = np.sin(x)
 7 
 8 plt.plot(x, y)
 9 plt.show()

sample-graph

What to do if you are not in a GUI environment

If you are not in a GUI environment such as connecting remotely with SSH, you will get the following error when executing the plt.plot (x, y) part of the above script.

_tkinter.TclError: no display name and no $DISPLAY environment variable

The following measures can be considered.

Action 1: Output the graph as a file

First, change the python settings.

/usr/lib64/python3.5/site-packages/matplotlib/mpl-data/matplotlibrc


 38 backend      : tkagg
 ↓
 38 #backend      : tkagg
 39 backend      : agg

In addition to the above modifications, modify the last line of the script "sample-graph.py" as follows.

 8 plt.show()
 ↓
 8 plt.savefig('sample-graph.png')

You can now output the specified graph to a file.

Action 2: Operate with GUI

If you are connecting remotely with ssh, do you want to operate the machine directly? If the machine is CUI, change it to GUI with the following command and operate it. What's good after that!

# systemctl isolate graphical.target

at the end

I think that you have built the python environment necessary for studying. (I took a lot of time to prepare the environment ...)

Recommended Posts

Build a python environment to learn the theory and implementation of deep learning
Build a Python environment and transfer data to the server
Quickly build a python environment for deep learning and data science (Windows)
Build and test a CI environment for multiple versions of Python
Othello-From the tic-tac-toe of "Implementation Deep Learning" (3)
I want to build a Python environment
[Python] I thoroughly explained the theory and implementation of logistic regression
[Python] I thoroughly explained the theory and implementation of decision trees
Othello-From the tic-tac-toe of "Implementation Deep Learning" (2)
Build a "Deep learning from scratch" learning environment on Cloud9 (jupyter miniconda python3)
Deep Learning from scratch-Chapter 4 tips on deep learning theory and implementation learned in Python
A memorandum of studying and implementing deep learning
A discussion of the strengths and weaknesses of Python
Build a Python machine learning environment with a container
[Python] I thoroughly explained the theory and implementation of support vector machine (SVM)
How to install the deep learning framework Tensorflow 1.0 in the Anaconda environment of Windows
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a machine learning Python environment on Mac OS
How to build a Django (python) environment on docker
Build a machine learning application development environment with Python
Build a python virtual environment with virtualenv and virtualenvwrapper
Othello ~ From the tic-tac-toe of "Implementation Deep Learning" (4) [End]
A reminder about the implementation of recommendations in Python
How to build a Python environment on amazon linux 2
Python Note: The mystery of assigning a variable to a variable
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
Build API server for checking the operation of front implementation with python3 and Flask
Build a machine learning environment
Steps to quickly create a deep learning environment on Mac with TensorFlow and OpenCV
Build a Python environment offline
Deep reinforcement learning 2 Implementation of reinforcement learning
[Deep Learning from scratch] Implementation of Momentum method and AdaGrad method
Build a python machine learning study environment on macOS sierra
Try to build a deep learning / neural network with scratch
A simple Python implementation of the k-nearest neighbor method (k-NN)
How to build a new python virtual environment on Ubuntu
(Now) Build a GPU Deep Learning environment with GeForce GTX 960
How to develop in a virtual environment of Python [Memo]
How to build a python2.7 series development environment with Vagrant
[Machine learning] I tried to summarize the theory of Adaboost
I want to know the features of Python and pip
Overview of Python virtual environment and how to create it
[Golang] Command to check the supported GOOS and GOARCH in a list (Check the supported platforms of the build)
What kind of environment should people who are learning Python for the first time build?
[Python] A program to find the number of apples and oranges that can be harvested
Environment construction of python and opencv
The story of Python and the story of NaN
Build a python3 environment on CentOS7
Learn the basics of Python ① Beginners
How to build a LAMP environment using Vagrant and VirtulBox Note
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
A story that struggled to handle the Python package of PocketSphinx
Build a Python environment on your Mac with Anaconda and PyCharm
How to check the memory size of a variable in Python
[Introduction to Python] I compared the naming conventions of C # and Python.
[Python] How to get the first and last days of the month
The simplest way to build a Spleeter usage environment using Windows
How to check the memory size of a dictionary in Python
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
[Python3] Define a decorator to measure the execution time of a function
Try to make a blackjack strategy by reinforcement learning ((1) Implementation of blackjack)