views:

109

answers:

3

Hi,

I'm trying to install Python from source on my Mac. (OS X 10.6.2, Python-2.6.5.tar.bz2) I've done this before and it was easy, but for some reason, this time after ./configure, and make, the sudo make install puts things some things in my home directory instead of in /usr/local/... where I expect. The .py files are okay, but not the .so files...

RobsMac Python-2.6.5 $ sudo make install
[...]
/usr/bin/install -c -m 644 ./Lib/anydbm.py /usr/local/lib/python2.6
/usr/bin/install -c -m 644 ./Lib/ast.py /usr/local/lib/python2.6
/usr/bin/install -c -m 644 ./Lib/asynchat.py /usr/local/lib/python2.6
[...]
running build_scripts
running install_lib
creating /Users/rob/Library/Python
creating /Users/rob/Library/Python/2.6
creating /Users/rob/Library/Python/2.6/site-packages
copying build/lib.macosx-10.4-x86_64-2.6/_AE.so -> /Users/rob/Library/ Python/2.6/site-packages
copying build/lib.macosx-10.4-x86_64-2.6/_AH.so -> /Users/rob/Library/ Python/2.6/site-packages
copying build/lib.macosx-10.4-x86_64-2.6/_App.so -> /Users/rob/Library/ Python/2.6/site-packages
[...]

Later, this causes imports that require those .so files to fail. For example...

RobsMac Python-2.6.5 $ python
Python 2.6.5 (r265:79063, Apr 28 2010, 13:40:18)
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import zlib
Traceback (most recent call last):
    File "", line 1, in
ImportError: No module named zlib

Any ideas what is wrong?

thanks, Rob

A: 

Have you checked the parameters or variables make expects? There probably is a make variable you can use to override that behavior. In any case, have you tried MacPorts? It may be a better solution to what you are trying to accomplish.

Francisco Soto
+1  A: 

In general, installing Python (or anything directly from the source) when it is already available on your system or when there are package managers that will install it for you, is not a very good idea. I strongly advise you against installing Python manually... Mac OS X 10.6 Snow Leopard comes with Python 2.6 out of the box; if you want a newer version of Python 2.6, then you should install MacPorts, and use:

sudo port install python26 python_select

You can then use the python_select to toggle between the system's version and MacPort's version.

If you are determined to install manually from the source, though, the way to do it would be to run "make distclean" (or untar the code separately again), then run "./configure --help" for a full list of configuration options. It is possible that on Mac OS X, it defaults to something other than /usr/local, in which case you could force it to install in that location by invoking configure with "./configure --prefix=/usr/local".

Michael Aaron Safyan
I'm aware of OS X's default Python, and package managers, but in my case I want to build from source. (I'm building software using Python and I need a version that I have total control over.) I typed "./configure". As I said above, it put most everything in /usr/local, which is the default prefix on OS X. It's just the .so files that went somewhere else. Some open source stuff doesn't compile easily on Mac, but with Python it used to work as easily as on Linux, and the Python site says the source tarball is for Linux, Unix, OS X. I'll look into this some more before trying MacPorts.
Rob N
@Rob, I still don't understand why you can't use the system's version of Python. Are you aware that the Mac's version of Python also has "easy_install" with which you can install whatever packages you need?
Michael Aaron Safyan
@Michael, I want the improvements that come with version 2.6.5 (my OS X has 2.6.2). I also want the same version in my development env (laptop) as I have on the live web server. Third, I've had experience on large Python projects where it was helpful or necessary to change the compile options. Fourth, I study interpreters and sometimes want to muck around in the C code.
Rob N
+2  A: 

Doh. I've answered my own question. Recently I created a ~/.pydistutils.cfg file, for some stupid reason. I forgot to delete that file. It's contents were:

[install]
install_lib = ~/Library/Python/$py_version_short/site-packages
install_scripts = ~/bin

make install calls setup.py, and this file was overriding the normal setup.py behavior.

Rob

Rob N