[Distutils] Can't count on -S to get a clean Python (at least on mac)

Zvezdan Petkovic zvezdan at computer.org
Sun Apr 8 00:42:41 CEST 2012


I know what you mean when you say clean Python.

However, for vendors, clean Python is the distribution that supports all their features and does not break their promises.  They do not promise Python with no additional extra packages.  For example, Apple has the support for the scripting bridge towards Objective-C libraries, py2app builder, and probably some other features that are obviously important to them.

On Apr 7, 2012, at 4:24 PM, Jim Fulton wrote:

> On my mac (Snow Leopard):
> 
> $ which python
> /usr/bin/python
> 
> $ python -S
> Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
> [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
>>>> import setuptools
>>>> setuptools.__file__
> '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/setuptools/__init__.pyc'
>>> 


The only thing this shows is that setuptools are in the Extras and that Extras are obviously always in sys.path.

This doesn't mean that site.py was loaded.

Do notice that site-packages are not included with python -S:

$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> '/Library/Python/2.6/site-packages' in sys.path
True
>>> '/Users/zvezdan/Library/Python/2.6/site-packages' in sys.path
True
>>> '/Users/zvezdan/.local/lib/python2.6/site-packages' in sys.path
True
>>> ^D

$ python -S
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
>>> import sys
>>> '/Library/Python/2.6/site-packages' in sys.path
False
>>> '/Users/zvezdan//Library/Python/2.6/site-packages' in sys.path
False
>>> '/Users/zvezdan/.local/lib/python2.6/site-packages' in sys.path
False
>>> ^D

The python2.6 man page says this:

-S	Disable the import of the module  site  and  the site-dependent
	manipulations of sys.path that it entails.

According to the tests above that promise is fulfilled.
Nothing site dependent was loaded.

> whimper

Your expectations of the -S option might be too high. :-)

> I haven't been able to reproduce this lamosity on any linux systems.


Probably because they are not trying to support a scripting bridge or an app builder.  Perhaps they do, but don't care if it breaks when -S is used. :-)  I'm pretty sure I've seen python installations on Linux that had their own warts.

I know you are trying to do something with this (probably for buildout) and that not being able to rely on -S is frustrating, to put it mildly.
I'm not arguing that, I just tried to point out what I thought was behind this behavior.

Regards,

	Zvezdan



More information about the Distutils-SIG mailing list