Cannot install python packages from source-code
Question: I need to install `PIL` (python imaging library) on my Ubunto10.4-32bit
(EDIT:64bit) machine on my python2.5.4-32bit. This question is also relevant
to any other source package I guess (among those that I need are
`RPyC`,`psyco` and `numpy`).

I downloaded the source-code since I can't find any neat package to do the job
and did a  
`sudo python2.5 setup.py install`.  
output:

    
    
    Could not find platform dependent libraries <exec_prefix>
    Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
    Traceback (most recent call last):
      File "setup.py", line 9, in <module>
        import glob, os, re, struct, string, sys
      File "/usr/lib/python2.5/struct.py", line 30, in <module>
        from _struct import Struct, error
    ImportError: No module named _struct
    

but

> > echo $PYTHONHOME  
> /usr

Well, in the file `struct.py` theres the line `from _struct import Struct,
error` This is part of the python source code itself so I really wonder whats
wrong with the python installation, since the code fails to import the module.  
I installed py2.5.4 by doing:

    
    
    ./configure --prefix=/usr
    make altinstall 
    

(using `make altinstall` since I need py26 as default python interpreter)

EDIT: This issue might have risen from mistakenly using a 64bit platform :)
and 32bit python2.5 . So anyhow problem solved by reducing unnecessary
complexities - switching to 32bit machine and porting app to python 2.6.


Answer: ### In short:

Try using the Ubuntu repository first. If the package isn't there, use
`easy_install`. If all fails, download the package directly to your source
folder.

### Ubuntu repository (the apt-get approach)

Ubuntu (10.04 and newer) has most mainstream packages are available with `apt-
get`. The naming convention is `python-NAME`, e.g. `python-imaging` or
`python-scipy`.

This is the best way to go, since the native package manager will handle any
dependencies and updates issues.

Run `apt-cache search python | grep "^python-" | less` to see a list of packages available for your system (I have over 1,200 in my 10.04 machine).

### Setuptools

For packages that are not part of the Ubuntu repository, you can use the
python `easy-install` tool. First, install the setup tool:

    
    
    sudo apt-get install python-setuptools
    

And you can install any Python package, e.g.
[colorworld](http://pypi.python.org/pypi/colorworld/0.3), using `easy-
install`:

    
    
    sudo easy_install colorworld
    

This gives you some degree of protection (e.g., handles dependencies) but
updates are generally manual, and it's a real pain to reinstall all these
packages in a new computer.

### Manual download

You can always download the source code to some directory and add it to your
`PYTHONPATH`. It's the best approach when you just need to evaluate a package
or apply some quick-and-dirty solution.

