As you’ll see in the following Python Enhancement Proposal (PEP-0453) article, Python 3.4 brings pip
and pyvenv
by default which is a great move to simplify Python dependencies management by offering a pre-built standard to download and install Python Modules and easily build virtual Python environments. In this article I’ll details how to install Python 3.4.2 from source and I’ll show you how to use pyvenv and pip.
Installation from source
On Debian, Ubuntu or deritative, first install the pre-requisite to compile Python 3.4 from source
# sudo apt-get install build-essential
Download the latest source code from python.org
$ wget https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgz
$ tar xvfz Python-3.4.2.tgz
$ cd Python-3.4.2
Configure the source tree with the location of the target installation
$ ./configure --prefix=~/python3.4
Compile Python 3.4.2
$ make
Install it to your target directory
$ make install
Virtual Environment
Linux distribution comes with their own version of Python, so to use the one you just compiled, the easiest way is to use the bundled pyvenv
tool.
Create a new virtual environment
$ cd myproject
$ ~/python3.4/bin/pyvenv env34
Activate this environment
$ source env34/bin/activate
You can now check everything looks good
$ python --version
Python 3.4.2
$ which python
You should also see (env34)
prepended to your shell prompt.
Python Package installation
After you’ve activated your virtual environment, you can now install Modules into it by using pip install
the usual way :
$ pip install pyYAML
It will download and install the requested package in env34/lib/python3.4/site-packages
You can search for Modules within the Python Package Index (PyPI)
$ pip search pecan
You can also upgrade pip
$ python -m ensurepip --upgrade
Deactivate your virtual environment
If you want to get back to the standard Python use
deactivate
I hope this article will help you simplify your Python development workflow.
Links
- Python 3 what’s new
- Python 3 documentation
- pyvenv documentation
- pip documentation