Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu packages needed to compile Python 2.7

I've tried to compile Python 2.7 on Ubuntu 10.4, but got the following error message after running make:

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             bsddb185           sunaudiodev     
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

What packages do I need? (setup.py was not helpful)

like image 607
deamon Avatar asked Sep 28 '10 13:09

deamon


People also ask

Does Python 2.7 have PIP?

PIP is automatically installed with Python 2.7.9+ and Python 3.4+ and it comes with the virtualenv and pyvenv virtual environments. Before you install PIP on Windows, check if PIP is already installed.

How do I make Python 2.7 default Ubuntu?

The simple answer is: uninstall python package. The more complex one is: do not install manually in /usr/local. Build a package with 2.7 version and then upgrade.


1 Answers

Assuming that you have all the dependencies installed (on Ubuntu that would be bunch of things like sudo apt-get install libdb4.8-dev and various other -dev packages, then this is how I build Python.

tar zxvf Python-2.7.1.tgz
cd Python-2.7.1

# 64 bit self-contained build in /opt
export TARG=/opt/python272
export CC="gcc -m64" 
export LDFLAGS='-Wl,-rpath,\$${ORIGIN}/../lib -Wl,-rpath-link,\$${ORIGIN}/../lib -Wl,--enable-new-dtags'
./configure --prefix=$TARG --with-dbmliborder=bdb:gdbm --enable-shared --enable-ipv6
make
make install

The only modules that don't build during make are:

_tkinter - I don't do GUI apps and would use wxWindows if I did
bsddb185 - horribly obsolete version of bdb
dl - deprecated in 2.6              
imageop - deprecated in 2.6
sunaudiodev - obsolete interface to some SparcStation device I think

Next I collect any .so files that are not already in the Python install directories and copy them over:

# collect binary libraries ##REDO THIS IF YOU ADD ANY ADDITIONAL MODULES##
cd /opt/python272
find . -name '*.so' | sed 's/^/ldd -v /' >elffiles
echo "ldd -v bin/python" >>elffiles
chmod +x elffiles
./elffiles | sed 's/.*=> //;s/ .*//;/:$/d;s/^              *//' | sort -u | sed 's/.*/cp -L & lib/' >lddinfo
# mkdir lib
chmod +x lddinfo
./lddinfo

And then add setuptools for good measure

#set the path
export PATH=/opt/python272/bin:$PATH

#install setuptools
./setuptools-0.6c11-py2.7.egg

At this point I can make a tarball of /opt/python272 and run it on any 64-bit Linux distro, even a stripped down one that has none of the dependencies installed, or a older distro that has old obsolete versions of the dependencies.

I also get pip installed but at this point there is a gap in my notes due to some failed struggles with virtualenv. Basically virtualenv does not support this scenario. Presumably I did easy_install pip and then:

export LD_RUN_PATH=\$${ORIGIN}/../lib
pip install cython
pip install {a whole bunch of other libraries that I expect to use}

After I'm done installing modules, I go back and rerun the commands to collect .so files, and make a new tarball. There were a couple of packages where I had to muck around with LDFLAGS to get them to install correctly, and I haven't done enough thorough testing yet, but so far it works and I'm using this Python build to run production applications on machines that don't have all the support libraries preinstalled.

like image 71
Michael Dillon Avatar answered Oct 07 '22 15:10

Michael Dillon