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

Diez B. Roggisch deets at nospam.web.de
Sun Jan 20 14:59:33 EST 2008


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



More information about the Python-list mailing list