Hi, I'm Chris

This blog is about programming, linux and other stuff.
Please don’t hesitate to contact me if you have any questions or suggestions for improvements!

Creating a virtual environment with python3.4 on Ubuntu 16.04 Xenial Xerus

Ubuntu 16.04 (Xenial Xerus) has been released last week and it ships with python version 3.5. Which is great, because it offers some new features for asynchronous programming. Unfortunately, one library (PySide) that I need for the superb jupyter qtconsole doesn’t support python 3.5 yet. Thus I needed a virtual environment with python 3.4:

Install dependencies:

sudo apt install build-essential checkinstall libreadline-gplv2-dev \
	libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev \
	libbz2-dev openssl

Get python source code:

mkdir -p $HOME/opt
cd $HOME/opt
curl -O https://www.python.org/ftp/python/3.4.4/Python-3.4.4.tgz
tar xzvf Python-3.4.4.tgz
cd Python-3.4.4

Configure & install

./configure --enable-shared --prefix=/usr/local LDFLAGS="-Wl,--rpath=/usr/local/lib"
sudo make altinstall

--enable-shared is neccessary for some libraries (like PySide), the --prefix is needed for reasons (more information in this so answer). make altinstall keeps your python3.5 installation as the default one.

Create a python3.4 virtualenv

Now we can create a new virtual environment and activate it:

> python3.4 -m venv myvirtualenv
> . myvirtualenv/bin/activate
(myvirtualenv) > python --version
Python 3.4.4

comments powered by Disqus