Make a Python 3.6 virtual environment in Xubuntu 16.04 using venv

04 Apr 2017 ᛫ 2 min read

SHARE:

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.

Install dependencies

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

Download the Python 3.6.1

wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

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 usr/local/lib/python3.6.1.

cd Python-3.6.1/
./configure --prefix /usr/local/lib/python3.6.1 --enable-ipv6

Run make and make install.

make
sudo make install

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.

/usr/local/lib/python3.6.1/bin/python3

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.
>>>

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

Activate the virtual environment

source ~/.venvs/python3.6.1/bin/activate

From here you can start developing using the Python version of your virtual environment. Write code, download libraries, etc.

SHARE:
comments powered by Disqus

You may also like:

ImportError - No module named resources_rc (QGIS Plugin Development) [SOLVED]

10 Apr 2017 ᛫ 1 min read

Adding images to the GUI of your custom QGIS 2.X plugin with Qt Designer

10 Apr 2017 ᛫ 2 min read

update-manager and update-notifier packages won't upgrade in Xubuntu 16.04 because of missing six module. [SOLVED]

06 Apr 2017 ᛫ 1 min read

Make virtual environments with different Python versions in Xubuntu 14.04

27 Mar 2017 ᛫ 3 min read

Create a bootable Windows 10 USB in Xubuntu 16.04 using mkusb

03 Apr 2017 ᛫ 1 min read

Support BNHR

If you find my website or any of the materials I share useful, you can consider donating to the cause below.

Donate and support BNHR

BNHR

[email protected]

Creative Commons License
Except when explicitly stated otherwise, this work and its contents by Ben Hur S. Pintor is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Other works (software, source code, etc.) referenced in this website are under their own respective licenses.
This site is powered by Jekyll and hosted on Github (view source)