You can put python from yum, but not always the latest version However, I don't like to increase the number of repositories unnecessarily, so I installed it from the source. The OS is CentOS 7.
# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
# cd /usr/local/src
# curl -O https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
# tar Jxf Python-3.6.2.tar.xz
# cd Python-3.6.2
# ./configure --prefix=/usr/local/python362 --with-ensurepip
# yum -y install zlib-devel openssl-devel tk-devel
# make
# make test
# make install
# ln -s /usr/local/python362/bin/python3.6 /bin/python3
# ln -s /usr/local/python362/bin/pip3.6 /bin/pip3
Is it troublesome to open the browser one by one? Search by curl. Suppress progress display with -s.
# curl -s https://www.python.org/downloads/source/ | grep -i latest
<li><a href="/downloads/release/python-362/">Latest Python 3 Release - Python 3.6.2</a></li>
<li><a href="/downloads/release/python-2713/">Latest Python 2 Release - Python 2.7.13</a></li>
The latest version is 3.6.2, so download it. -O is the same name as the remote and is output locally. Since it is a compilation before this, the location should be user / usr / local / src.
# cd /usr/local/src
# curl -O https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
Unzip. The xz format can be decompressed with the J option of tar.
# tar Jxf Python-3.6.2.tar.xz
Run configure. As for the installation destination, considering that the latest version will be installed later, I want to set it to / usr / local / python362, so specify prefix in configure. By the way, pip is used a lot, so specify to install it at the same time.
# cd Python-3.6.2
# ./configure --prefix=/usr/local/python362 --with-ensurepip
By executing configure, system libraries, commands, etc. Check what you need to compile and Create a Makefile that includes the prefix given as an option.
Next, install the pip prerequisite package (if not).
# yum -y install zlib-devel openssl-devel tk-devel
Next, compile based on the Makefile with make.
# make
Next, test if the make test works.
# make test
(Abbreviation)
zipimport.ZipImportError: can't decompress data; zlib not available
(Abbreviation)
Tests result: FAILURE
make: *** [test]Error 1
If it doesn't work, it looks like this. (Error when pip premise zlib is not included)
After SUCCESS, finally install with make install.
# make install
Create links to python3 and pip3 under / bin.
# ln -s /usr/local/python362/bin/python3.6 /bin/python3
# ln -s /usr/local/python362/bin/pip3.6 /bin/pip3
Finally, display the version and check.
# python3 -V
Python 3.6.2
# pip3 -V
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
That's it.
** I was addicted to doing this at first, so I will leave it as a lesson. ** **
The existing link is a link to version 2, so switch this. By the way, I'll also make a pip link.
# which python
/bin/python
# ls -l /bin/python
lrwxrwxrwx.1 root root 7 May 2 13:00 /bin/python -> python2
# mv /bin/python /bin/_python
# ln -s /usr/local/python362/bin/python3.6 /bin/python
# ln -s /usr/local/python362/bin/pip3.6 /bin/pip
Finally, display the version and check.
# python -V
Python 3.6.2
# pip -V
pip 9.0.1 from /usr/local/python362/lib/python3.6/site-packages (python 3.6)
It didn't end with * ... *
Then I installed it and tried to put it in scipy with pip.
# pip install scipy
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Oh yeah, you need SSL. So let's put openssl-devel in yum. (* Actually, remake is required)
# yum -y install openssl-devel
File "/bin/yum", line 30
except KeyboardInterrupt, e:
^
SyntaxError: invalid syntax
** (゜ ゜)… ** I got stuck with a face for a while. The reason is The way to write except has changed from Python3.
Therefore, shebang was changed as follows as a first aid measure. I don't really want to modify people's scripts, but ...
#!/usr/bin/python2
If you think it will work with
# yum -y install openssl-devel
(Abbreviation)
Downloading packages:
File "/usr/libexec/urlgrabber-ext-down", line 28
except OSError, e:
^
SyntaxError: invalid syntax
It ends with the cancellation of the user
** Mata Omae? **
… So don't mess with the existing ones.
Recommended Posts