Installing Python 3.6.1 from source

This is a revisiting of a previous post setting up Ubuntu 16.04LTS. In this previous post I installed Python 3.5 from the Ubuntu/Debian repo. It was a breeze. Now that I want Python 3.6.1, however, it is not as easy. Some dependencies are not well documented and I had to find them through trial-and-error. This post documents the process.

This is a work in progress as you will see we are stuck in some last dependencies.

System spec

Ubuntu 16.04 LTS

Steps

Initial run

  1. Download source
  2. ./configure
  3. make

This will show a list of Ubuntu packages that are missing for optional packages. It is fine if you don’t really care to use those features, though. Normal system programming / data science applications are not really affected.

Ubuntu packages to install

This may not be a complete list, but here are some of them. It should be possible to sudo apt-get install all of them .

Packages Other packages
libc6
build-essential
libreadline6 -dev
libsqlite3-dev
libbz2-dev
libgdbm-dev
liblzma5 liblzma-dev/liblzma-doc
libssl-dev -doc
libncurses5 -dev/-doc
libncursesw5 -dev/-doc
tk-dev

Alternatively just copy paste the following

1
2
3
4
5
6
7
8
9
10
sudo apt-get install libc6, build-essential
sudo apt-get install libreadline6 libreadline6-dev
sudo apt-get install libsqlite3-dev
sudo apt-get install libbz2-dev
sudo apt-get install libgdbm-dev
sudo apt-get install liblzma5, liblzma-dev, liblzma-doc
sudo apt-get install libssl-dev, libssl-doc
sudo apt-get install libncurses5, libncurses5-dev, libncurses5-dbg
sudo apt-get install libncursesw5, libncursesw5-dev, libncursesw5-dbg
sudo apt-get install tk-dev

Tkinter

Note that previously there was a problem with Tkinter dependency and I was not able to find the correct dependency.
But this is officially solved by installing tk-dev package.

Version control

I recommend pyenv for managing multiple versions of python. It integrates well with virtualenv so you can not only swtich between python versions seamlessly but also create virtual environment of desired python version on the fly. Now that all Ubuntu comes with Py2.7 and Py3.5 built-in this will be handy.

The easiest way to install pyenv is by running the auto-installer

1
$ curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash</div>

With all the dependencies installed. We can install with pyenv this way

1
2
export CONFIGURE_OPTS="--enable-optimizations"
pyenv install -v 3.6.1

The first line asks configure to use optimization for Python 3.6. See the discussion about the flag. According to here the flag will make the compiled binary 10% faster, which I think is worth trying out.