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.
- Get the source:
wget http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2
- Untar it:
tar jxf ./Python-3.3.0.tar.bz2
cd Python-3.3.0
Just make the changes in the setup.py itself if you are not going to make multiple installations
-
cp setup.py patched_setup.py
to create the copy ofsetup.py
where we are going make the changes. -
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 = []
-
Change lib_dirs value with:
lib_dirs = self.compiler.library_dirs + [ '/lib64', '/usr/lib64', '/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu' ]
-
Create the patch:
diff -u setup.py patched_setup.py > setup_py.patch
-
We can now delete the
patched_setup.py
.
Now we have our patch in setup_py.patch
.
- Copy
patched_setup.py
to the same directory of thesetup.py
you want to patch and execute:patch setup.py < setup_py.patch
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
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"
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.
First compile make
and, once finished, install it with sudo make install
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.
- Create a Virtual Environment in home directory:
/opt/python3.3/bin/pyvenv ~/venv3.3
- Activate the virtualenv:
source ~/venv3.3/bin/activate
- Install distribute tools:
wget http://python-distribute.org/distribute_setup.py && python distribute_setup.py
- Install pip:
easy_install pip
- Have fun!