Skip to content

Instantly share code, notes, and snippets.

@fespino
Last active December 17, 2015 20:09
Show Gist options
  • Save fespino/5665706 to your computer and use it in GitHub Desktop.
Save fespino/5665706 to your computer and use it in GitHub Desktop.
Python 3.3 installation in Ubuntu 12.04 x86_64

Python 3.3 install in Ubuntu 12.04 x86_64

I had some troubles using Python 3.3 in Ubuntu running on x86_64 architecture. This gist is just a reminder of how I solved it.

Getting the source

  1. Get the source: wget http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2
  2. Untar it: tar jxf ./Python-3.3.0.tar.bz2
  3. cd Python-3.3.0

Creating the patch

Just make the changes in the setup.py itself if you are not going to make multiple installations

  1. cp setup.py patched_setup.py to create the copy of setup.py where we are going make the changes.

  2. Open patched_setup.py and look for the block of code that reads (around line 514):

     # lib_dirs and inc_dirs are used to search for files;
     # if a file is found in one of those directories, it can
     # be assumed that no additional -I,-L directives are needed.
     if not cross_compiling:
         lib_dirs = self.compiler.library_dirs + [
             '/lib64', '/usr/lib64',
             '/lib', '/usr/lib',
             ]
         inc_dirs = self.compiler.include_dirs + ['/usr/include']
     exts = []
     missing = []
    
  3. Change lib_dirs value with:

     lib_dirs = self.compiler.library_dirs + [
            	'/lib64', '/usr/lib64',
             '/lib', '/usr/lib',
     '/usr/lib/x86_64-linux-gnu'
             ]
    
  4. Create the patch: diff -u setup.py patched_setup.py > setup_py.patch

  5. We can now delete the patched_setup.py.

Now we have our patch in setup_py.patch.

Patching It

setup.py

  1. Copy patched_setup.py to the same directory of the setup.pyyou want to patch and execute: patch setup.py < setup_py.patch

Installing it

Ubuntu packages

sudo apt-get install build-essential python-openssl libncurses5-dev libbz2-dev \ libreadline-gplv2-dev libsqlite3-dev libssl-dev libgdbm-dev tcl8.5-dev tk8.5-dev

Environment variables

Change the CPPFLAGS and LDFLAGS environtment variables to:

env CPPFLAGS="-I/usr/lib/x86_64-linux-gnu" LDFLAGS="-L/usr/include/x86_64-linux-gnu"

Configure

Use the --prefix=/path/to/python flag to choose your preferred Python installation path. I used:

./configure --prefix=/opt/python3.3

So my Python 3.3 it's going to be in /opt/python3.3 directory.

Install

First compile make and, once finished, install it with sudo make install

Creating a py3 command linked to our new python

sudo ln -s /opt/python3.3/bin/python3 /usr/local/bin/py3

Now if you execute py3 you should see something similar:

Python 3.3.0 (default, May 28 2013, 17:47:38)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.

Creating a virtual environment

  1. Create a Virtual Environment in home directory: /opt/python3.3/bin/pyvenv ~/venv3.3
  2. Activate the virtualenv: source ~/venv3.3/bin/activate
  3. Install distribute tools: wget http://python-distribute.org/distribute_setup.py && python distribute_setup.py
  4. Install pip: easy_install pip
  5. Have fun!

Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment