Installing Python 3.4 and setting up a virtualenv

As an update to my snippet on installing Python 3, the installation and setup of virtualenvs with Python 3.4 is a little different, namely because python 3.4 ships with its own virtual environment manager, Pyvenv.

1. Download the tarball and extract

$ cd /tmp
$ wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tgz
$ tar -xvf Python-3.4.0.tgz

2. Run configure using the –prefix flag to specify installation location

$ ./configure --prefix=/usr/bin/python3.4

3. Make and install

$ make && sudo make install

4. Use the `pyvenv` to make a virtualenv, supplying the location of your virtualenvs

$ /usr/bin/python3.4/bin/pyvenv3.4 ~/.envs/py34

5. Activate your virtualenv

$ . ~/.envs/py34/bin/activate

6. Check Python version

$ python -V
Python 3.4.0

You might want to also make a bash alias to facilitate the creation of virtual environments this way.

UPDATE

I have noticed that often when compiling Python 3.X from source it complains about not being able to find the Bz2 module.

Some very good instructions for solving this are here: http://justanyone.blogspot.ca/2012/07/compiling-python-with-bz2.html

Basically you just need to make Bz2 prior to Python.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s