Linux/Win32 func. to get Python instdir (not exedir) + site-packages => extensions mgmt
sjmachin at lexicon.net
Mon Jan 21 00:09:17 CET 2008
On Jan 21, 8:58 am, pythonewbie <epro... at gmail.com> wrote:
> I just would like to know if I would ALWAYS find the install directory
> in sys.path and site-packages directory in sys.path on any Win32
> platform and sys.path and site-packages directory in sys.path on
> any Linux platform.
> If the reply is : "YES you can be sure of it !"
No, you can't be sure of any such thing. In general in computing
assuming a fixed position in a variable-length list is a nonsense.
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> from pprint import pprint as pp
>>> pp([(x, p) for x, p in enumerate(sys.path)])
Something like this might be more reliable:
>>> import sys, re
>>> for p in sys.path:
... m = re.match(r'(.*)[\\/][Ll]ib[\\/]site-packages$', p)
... if m:
... print m.group(1, 0)
... raise Exception('Huh?')
> All would be great for me and I would be ready to create a script to
> detect with a reliable manner the installation dir. et site-packages
> dir. for all my Linux/Win32 Python apps.
You mentioned Python versions back to 2.1 earlier. However you
evidently haven't bothered to start up Python 2.1 and look at
Python 2.1.3 (#35, Apr 8 2002, 17:47:50) [MSC 32 bit (Intel)] on
Type "copyright", "credits" or "license" for more information.
>>> import sys; sys.path
['', 'C:\\junk', 'C:\\python21\\DLLs', 'C:\\python21\\lib', 'C:\
plat-win', 'C:\\python21\\lib\\lib-tk', 'C:\\python21']
Before you rush out and re-invent the wheel, have a look at this:
You may like to re-ask your questions on the distutils mailing list.
More information about the Python-list