Make a Python 3.6 virtual environment in Xubuntu 16.04 using venv
Xubuntu 16.04 comes packaged with Python 3.5.2. As is standard practice, it’s not advisable to update or change the Python version of your distribution lest you risk possible problems in your system. One of the better options if you want to use different python versions in your machine is to use virtual environments. Since version 3.4, Python has come packaged with venv – a library for making virtual environments. This post will show you how to install Python 3.6.1 in Xubuntu 16.04 and use venv to create a virtual environment running Python 3.6.1.
sudo apt-get install -y \ autotools-dev \ blt-dev \ build-essential \ bzip2 \ dpkg-dev \ g++-multilib \ gcc-multilib \ libbluetooth-dev \ libbz2-dev \ libexpat1-dev \ libffi-dev \ libffi6 \ libffi6-dbg \ libgdbm-dev \ libgpm2 \ libncursesw5-dev \ libreadline-dev \ libsqlite3-dev \ libssl-dev \ libtinfo-dev \ mime-support \ net-tools \ netbase \ python-crypto \ python-dev \ python-mox3 \ python-pil \ python-pip \ python-ply \ python-setuptools \ python-smbus \ quilt \ tk-dev \ zlib1g-dev
2. Download the Python 3.6.1
3. Unpack, Configure, and Compile
The line below will unpack the contents of the archive to a Python-3.6.1 directory.
tar xfz Python-3.6.1.tgz
Go to the directory and configure where you want to install the new Python version. Here we’ll install it in
cd Python-3.6.1/ ./configure --prefix /usr/local/lib/python3.6.1 --enable-ipv6
Run make and make install.
sudo make install
4. Test if the Python version was compiled successfully
Remember where we installed our new Python version? Let’s check if the compiler will run.
Enter the following in your command line.
It should result in something similar below.
Python 3.6.1 (default, Apr 4 2017, 12:20:28) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
5. Make a Virtual Environment using the version of Python you just installed.
/usr/local/lib/python3.6.1/bin/python3 -m venv <location-of-virtualenv>
I tend to put all my virtual environments in a single directory. I recommend having something like a
.venvs directory for that purpose.
/usr/local/lib/python3.6.1/bin/python3 -m venv ~/.venvs/python3.6.1
6. Activate the virtual environment
From here you can start developing using the Python version of your virtual environment. Write code, download libraries, etc.