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

pythonewbie eproust at gmail.com
Sun Jan 20 16:58:13 EST 2008


On 20 jan, 20:59, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> pythonewbie schrieb:
>
>
>
> > On 20 jan, 19:50, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> >> pythonewbie schrieb:
>
> >>> On 20 jan, 12:20, Christian Heimes <li... at cheimes.de> wrote:
> >>>> pythonewbie wrote:
> >>>>> I am stucked on creating a function to get the Python install
> >>>>> directory (and site-packages directory) with a 100% reliable method...
> >>>> Only one method is 100% reliable:
> >>>> try:
> >>>>     import yourextension
> >>>> except ImportError:
> >>>>     available = False
> >>>> else:
> >>>>     available = True
> >>>> Christian
> >>> Hi Christian,
> >>> OK thanks, interesting to detect if an extension is available or not.
> >>> But for different reasons I also want to get the absolute path of
> >>> Python install directory (not only the executable under Linux) and
> >>> site-packages directory.
> >>> How could I proceed ?
> >> Maybe sys.path is a starter?
>
> >> Diez
>
> > Yes, it is, but my problem is that I am not sure to find the
> > information I need at the same position of the list generated by
> > sys.path.
>
> > I explain, for Win32, I find install directory using sys.path[6] and
> > site-package directory using sys.path[7], for Linux I find install
> > directory using sys.path[2] and site-package directory using
> > sys.path[6].
>
> > For my tests, I have used XP Pro and Ubuntu Gutsy.
>
> > I am not sure to find these information at the same position in the
> > sys.path list using Win9x, Win2k, Ubuntu Dapper, Redhat FC6, FreeBSD
> > and using Python v2.1 2.2 2.3 etc ?
>
> > This why I'm asking experienced programmers of this usenet group for
> > advices.
>
> Sorry, I missed your first post. However, I don't see what your problem
> actually is. If you want to look for any extension, you need to consider
> whatever can be seen in the sys.path. So what do you care about the
> order of them?
>
> Diez

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.

If the reply is : "YES you can be sure of it !"

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.

Thanks for your interest on this topic.





More information about the Python-list mailing list