Linux/Win32 func. to get Python instdir (not exedir) + site-packages => extensions mgmt

John Machin sjmachin at lexicon.net
Mon Jan 21 10:23:34 CET 2008


On Jan 21, 8:12 pm, pythonewbie <epro... at gmail.com> wrote:
> On 21 jan, 09:53, pythonewbie <epro... at gmail.com> wrote:
>
>
>
> > On 21 jan, 05:31, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
>
> > > On Sun, 20 Jan 2008 13:58:13 -0800 (PST), pythonewbie
> > > <epro... at gmail.com> declaimed the following in comp.lang.python:
>
> > > > I just would like to know if I would ALWAYS find the install directory
> > > > in sys.path[6] and site-packages directory in sys.path[7] on any Win32
> > > > platform and sys.path[2] and site-packages directory in sys.path[6] on
> > > > any Linux platform.
>
> > >         Unlikely...
>
> > > >>> sys.path[6]
>
> > > 'E:\\Python24\\lib\\site-packages\\decoratortools-1.4-py2.4.egg'>>> sys.path[2]
>
> > > 'E:\\Python24\\lib\\site-packages\\ctypes-1.0.1-py2.4-win32.egg'>>> sys.path
>
> > > ['', 'E:\\Python24\\lib\\site-packages\\pyopengl-3.0.0a5-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\ctypes-1.0.1-py2.4-win32.egg',
> > > 'E:\\Python24\\lib\\site-packages\\sqlobject-0.7.6-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\celementtree-1.0.5_20051216-py2.4-win32.egg',
> > > 'E:\\Python24\\lib\\site-packages\\configobj-4.4.0-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\decoratortools-1.4-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\ruledispatch-0.5a0.dev_r2306-py2.4-win32.egg',
> > > 'E:\\Python24\\lib\\site-packages\\formencode-0.7.1-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\pastescript-1.3.4-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\elementtree-1.2.6_20050316-py2.4-win32.egg',
> > > 'E:\\Python24\\lib\\site-packages\\simplejson-1.7.1-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\cherrypy-2.2.1-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\turbocheetah-0.9.5-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\turbojson-1.0-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\pyprotocols-1.0a0dev_r2302-py2.4-win32.egg',
> > > 'E:\\Python24\\lib\\site-packages\\pastedeploy-1.3-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\paste-1.3-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\cheetah-2.0rc8-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\setuptools-0.6c6-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\turbogears-1.0.3.2-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\turbokid-1.0.2-py2.4.egg',
> > > 'E:\\Python24\\lib\\site-packages\\kid-0.9.6-py2.4.egg',
> > > 'e:\\python24\\lib\\site-packages\\scipy',
> > > 'C:\\WINDOWS\\system32\\python24.zip', 'e:\\UserData\\Dennis Lee
> > > Bieber\\My Documents', 'E:\\Python24\\DLLs', 'E:\\Python24\\lib',
> > > 'E:\\Python24\\lib\\plat-win', 'E:\\Python24\\lib\\lib-tk',
> > > 'E:\\Python24\\Lib\\site-packages\\pythonwin', 'E:\\Python24',
> > > 'E:\\Python24\\lib\\site-packages',
> > > 'E:\\Python24\\lib\\site-packages\\Numeric',
> > > 'E:\\Python24\\lib\\site-packages\\PIL',
> > > 'E:\\Python24\\lib\\site-packages\\win32',
> > > 'E:\\Python24\\lib\\site-packages\\win32\\lib',
> > > 'E:\\Python24\\lib\\site-packages\\wx-2.8-msw-unicode']
>
> > > >>> os.environ["PATH"]
>
> > > 'E:\\Python24\\;C:\\GNAT\\bin;C:\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\PROGRA~1\\MySQL\\MySQL
> > > Server 5.0\\bin;C:\\Program Files\\SciTE;C:\\Program
> > > Files\\Java\\jre1.6.0_03\\bin;C:\\Program
> > > Files\\Java\\jdk1.6.0_03\\bin;C:\\Program Files\\Common
> > > Files\\Adobe\\AGL;C:\\MSSQL7\\BINN;c:\\PROGRA~1\\sdb\\programs\\bin;c:\\PROGRA~1\\sdb\\programs\\pgm;C:\\Tcl\\bin;C:\\Program
> > > Files\\Common Files\\Roxio Shared\\DLLShared\\;C:\\Program Files\\Common
> > > Files\\Roxio Shared\\9.0\\DLLShared\\;e:\\Python24\\Scripts;c:\\Regina'
>
> > > --
> > >         Wulfraed        Dennis Lee Bieber               KD6MOG
> > >         wlfr... at ix.netcom.com              wulfr... at bestiaria.com
> > >                 HTTP://wlfraed.home.netcom.com/
> > >         (Bestiaria Support Staff:               web-a... at bestiaria.com)
> > >                 HTTP://www.bestiaria.com/
>
> > OK Denis Lee, I see now. I appreciate your clear and simple to
> > understand reply.
>
> > All posts on this topic, have been appreciated a lot... Thanks to all
> > helpers.
>
> > Cheers
>
> Hi John Machin,
>
> Your code :
>
> >>> import sys, re
> >>> for p in sys.path:
>
> ...    m = re.match(r'(.*)[\\/][Ll]ib[\\/]site-packages$', p)
> ...    if m:
> ...       print m.group(1, 0)
> ...       break
> ... else:
> ...    raise Exception('Huh?')
> ...
>
> Does not work on my PC : Traceback (most recent call last):
>   File "/home/eproust/john-machin_recup_rep_site-packages.py", line 9,
> in <module>
>     raise Exception('Huh?')
> Exception: Huh?

My palantir is in the workshop, so you'll have to tell me what's in
sys.path on your machine.

>
> Even if I remove all code below the else: part of the script...

Uh-huh.



More information about the Python-list mailing list