2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

install Python3.6.8 to ubuntu

Last updated at Posted at 2019-03-12

Introduction

Probably most popular version of Python is '3.6.x'. I'm explain this version.

confirm version already installed Python on ubuntu 16.04LTS

bash
$ python3.5 -V
bash
python3.5.2

install Python3 'deb' libraries

necessary 'deb' libraries list

library name use
build-essential building Python on ubuntu
python3-dev Python3 developer tools
libsqlite3-dev SQLite3 library
libreadline6-dev readline Python module
libgdbm-dev dbm.gnu Python module
zlib1g-dev zlib Python module
libbz2-dev bz2 Python module
sqlite3 sqlite3 Python module
tk-dev tkinter Python module
zip zip Python module
libssl-dev ssl Python module

command for Python3 'deb' libraries install on ubuntu

bash
$ sudo apt -y install build-essential
$ sudo apt -y install python3-dev
$ sudo apt -y install libsqlite3-dev
$ sudo apt -y install libreadline6-dev
$ sudo apt -y install libgdbm-dev
$ sudo apt -y install zlib1g-dev
$ sudo apt -y install libbz2-dev
$ sudo apt -y install sqlite3
$ sudo apt -y install tk-dev
$ sudo apt -y install zip
$ sudo apt -y install libssl-dev

or only 1 line command below.

bash
$ sudo apt-get -y install build-essential python3-dev  libsqlite3-dev libreadline6-dev libgdbm-dev zlib1g-dev libbz2-dev sqlite3 tk-dev zip libssl-dev 

If proxy server over from local LAN then you must add proxy setting parameter to command

bash
$ sudo apt -y -o Acquire::http::proxy="http://username:password@proxy.hoge.domain.name:portno/" install build-essential

build new version 'Python3.6.8' from source files

If other versions of python are same operations available. By the way, recent version is '3.8.0' at 15, March 2019.

proxy setting if ubuntu server connect to internet via from proxy server

bash
$ sudo vim /etc/wgetrc
  • add 3 lines blow
bash
http_proxy=http://user id:password@proxy.xxx.xxx:port no/
https_proxy=http://user id:password@proxy.xxx.xxx:port no/
ftp_proxy=user id:password@proxy.xxx.xxx:port no/

ftp download compression file 'Python-3.6.8.tgz' from source files

$ wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
--2019-03-12 14:01:20--  https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
www.python.org (www.python.org) をDNSに問いあわせています... 151.101.88.223, 2a04:4e42:15::223
www.python.org (www.python.org)|151.101.88.223|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 22710891 (22M) [application/octet-stream]
`Python-3.6.8.tgz' に保存中

Python-3.6.8.tgz                             100%[==============================================================================================>]  21.66M  13.2MB/s    時間 1.6s

2019-03-12 14:01:22 (13.2 MB/s) - `Python-3.6.8.tgz' へ保存完了 [22710891/22710891]

extract Python-3.6.8.tgz to './Python-3.6.8' directory

bash
$ tar xf Python-3.6.8.tgz
$ ll
bash
合計 22224
drwxr-xr-x  5 vagrant vagrant     4096  3月 12 14:05 ./
drwxr-xr-x  4 root    root        4096  3月  9 18:20 ../
-rw-------  1 vagrant vagrant      211  3月 11 13:48 .bash_history
-rw-r--r--  1 vagrant vagrant      220  3月  8 08:21 .bash_logout
-rw-r--r--  1 vagrant vagrant     3796  3月  9 18:55 .bashrc
drwx------  2 vagrant vagrant     4096  3月  9 18:20 .cache/
-rw-r--r--  1 vagrant vagrant      655  3月  8 08:21 .profile
drwx------  2 vagrant vagrant     4096  3月  9 18:20 .ssh/
-rw-------  1 vagrant vagrant     1050  3月 10 02:38 .viminfo
-rw-rw-r--  1 vagrant vagrant      171  3月 12 14:01 .wget-hsts
drwxr-xr-x 16 vagrant vagrant     4096 12月 19  2017 Python-3.6.8/
-rw-rw-r--  1 vagrant vagrant 22710891 12月 19  2017 Python-3.6.8.tgz

create 'Makefile' by configure script

change directory

bash
$ cd Python-3.6.8/
$ pwd
bash
/home/vagrant/Python-3.6.8

create 'Makefile' for target directory '/opt/python3.6.8'

bash
$ ./configure --prefix=/opt/python3.6.8
bash
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
...................
.....Omission......
...................
creating Modules/Setup.local
creating Makefile

If you want a release build with all stable optimizations active (PGO, etc),
please run ./configure --enable-optimizations

confirm existing 'Makefile'

bash
$ ll Makefile
bash
-rw-rw-r-- 1 vagrant vagrant 69199  3月 12 14:12 Makefile

compile in order to 'Makefile'

bash
$ make
bash
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers   -I. -I./Include    -DPy_BUILD_CORE -o Programs/python.o ./Programs/python.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers   -I. -I./Include    -DPy_BUILD_CORE -o Parser/acceler.o Parser/acceler.c
...................
.....Omission......
...................
# Replace makefile compat. variable references with shell script compat. ones;  ->
LC_ALL=C sed -e 's,\$(\([A-Za-z0-9_]*\)),\$\{\1\},g' < Misc/python-config.sh >python-config
# On Darwin, always use the python version of the script, the shell
# version doesn't use the compiler customizations that are provided
# in python (_osx_support.py).
if test `uname -s` = Darwin; then \
        cp python-config.py python-config; \
fi

test Makefile

bash
$ sudo make test

install Python3.6.8 in order to 'install' session in 'Makefile'

bash
$ sudo make install
Creating directory /opt/python3.6.8/bin
Creating directory /opt/python3.6.8/lib
if test "no-framework" = "no-framework" ; then \
        /usr/bin/install -c python /opt/python3.6.8/bin/python3.6m; \
else \
        /usr/bin/install -c -s Mac/pythonw /opt/python3.6.8/bin/python3.8m; \
fi
...................
.....Omission......
...................
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-9.0.1 setuptools-28.8.0

confirm installed Python3.6.8 version

$ /opt/python3.6.8/bin/python3.6 -V
Python 3.6.8

create symbolic link 'python3.8'

$ sudo ln -s /opt/python3.8.4/bin/python3.8 /usr/local/bin/python3.8

confirm symbolic link command 'python3.6'

$ python3.6 -V
Python 3.6.8

create symbolic link 'pip'

$ sudo ln -s /opt/python3.6.8/bin/pip3.6 /usr/local/bin/pip

confirm symbolic link command 'pip'

bash
$ pip --version
bash
pip 18.1 from /opt/python3.6.8/lib/python3.6/site-packages/pip (python 3.6)
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?