Installing Python3.6 in Ubuntu 16.04 LTS Instance Server
Posted on May 23, 2018 in tutorial
Here is the step by step guide to install Python 3.6.3
in your AWS EC2's Ubuntu 16.04 server instance or in your local machine with Ubuntu 16.04 LTS Desktop or in Linux Mint.
Note: If you are using Ubuntu 18.04 LTS, then it ships with Python 3.6.3 by default.
Check which Python version is pre-installed in the system by typing $ python3 -V
in the terminal. Generally it is Python 3.5.2
for Ubtuntu 16.04 LTS.
Pre-requisites
-
First you need to upgrade and update your system.
$ sudo apt update && sudo apt -y upgrade
-
Then you need to install
zlib1g-dev
package because of this issue.$ sudo apt -y install zlib1g-dev
To make sure it is installed correctly, type$ cat /usr/include/zlib.h
. It'll show you the source ofzlib
header file. -
Because of this issue, you also have to install another package called
libreadline-dev
$ sudo apt install libreadline-dev
-
Now, install
build-essential
and other bunch of stuffs which is required byPython 3.6.3
afterwards.$ sudo apt install build-essential checkinstall libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
These packages are needed for setting up SSL for downloading packages over PIP, for setting up
sqlite
,g++
and so on. -
Export
LD_LIBRARY_PATH
for secure SSL connection.$ export LD_LIBRARY_PATH=/usr/local/ssl/lib/
Begin installation of Python 3.6.3
-
First, download tar zipped file from Python FTP server.
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
-
Extract the zipped file:
$ tar zxvf Python-3.6.3.tgz
-
Move Python3.6.3 directory to
/opt/
directory andcd
into it.$ sudo mv Python-3.6.3 /opt/
$ cd /opt/Python-3.6.3/
-
Configure Python directory.
$./configure --enable-optimizations
-
Make it:
$ make
-
Test the Make if you want (this is optional)
$ make test
-
Install it via Make:
sudo make install
-
Verify that Python 3.6.3 is installed in your system by typing
$ python3
If it again shows Python 3.5.2 then type
$ python3.6
. To make things easier, set up an alias. To set up alias do the following:Edit
.bashrc
file located in your home directory.$ nano ~/.bashrc
Add following line at the end
alias python3=/usr/local/bin/python3.6
At this point, Python 3.6.3 is correctly installed in your system
Further steps:
-
Make sure yout PIP is correct. In Python2 is
pip
and in Python3 itspip3
$ pip3 -V
shows you which Python it is pointing to. -
If you are using
pyodbc
then you need to installunixodbc-dev
$ sudo apt -f install unixodbc-dev
Then you can insall
pyodbc
with:$ pip3 install pyodbc