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

P

pythonewbie

Hi all,

I am newbie in Python, my wish would be to create python applications
for both Linux/Win32.

I am stucked on creating a function to get the Python install
directory (and site-packages directory) with a 100% reliable method...

My goal is to verify if an/several extension(s) are installed and to
automatically install the missing ones on Linux or Win32.

I have tested sys.executable and sys.path, but I am not sure to be
able to get what I need on different versions of Python and different
platforms.

Google was not a good friend on this, so I am very interested on how
you implement such a function.

Cheers.
 
C

Christian Heimes

pythonewbie said:
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
 
P

pythonewbie

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 ?
 
D

Diez B. Roggisch

pythonewbie said:
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
 
P

pythonewbie

pythonewbie schrieb:








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.
 
M

Michael L Torrie

pythonewbie said:
Hi all,

I am newbie in Python, my wish would be to create python applications
for both Linux/Win32.

I am stucked on creating a function to get the Python install
directory (and site-packages directory) with a 100% reliable method...

My goal is to verify if an/several extension(s) are installed and to
automatically install the missing ones on Linux or Win32.

I have tested sys.executable and sys.path, but I am not sure to be
able to get what I need on different versions of Python and different
platforms.

Google was not a good friend on this, so I am very interested on how
you implement such a function.

On both windows and Linux, installing stuff into the python install dir
requires root or administrative privileges, something most linux users
won't have unless they sudo. So if the extensions you need are missing,
and you are distributing them yourself, why not just add them into the
path at runtime, rather than messing with the user's system?

As for obtaining the installation path, the setup.py that often comes
with python modules like ldaptor, seems to be able to figure it out.
I'd check there. I think setup.py is created with distutils.
 
D

Diez B. Roggisch

pythonewbie said:
pythonewbie schrieb:



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
 
P

pythonewbie

pythonewbie schrieb:


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.
 
M

Martin v. Löwis

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.

The Python install directory is available as sys.prefix. The
site-packages directory is
sys.prefix+"lib/python"+x.y+"/site-packages (where x.y is from
sys.version_info).

HTH,
Martin
 
P

pythonewbie

The Python install directory is available as sys.prefix. The
site-packages directory is
sys.prefix+"lib/python"+x.y+"/site-packages (where x.y is from
sys.version_info).

HTH,
Martin
http://forum.ubuntu-fr.org/viewtopic.php?id=184199
'/usr/lib/python2.5/site-packages'

get_python_lib(plat_specific=0, standard_lib=0, prefix=None)
Return the directory containing the Python library (standard
or
site additions).

If 'plat_specific' is true, return the directory containing
platform-specific modules, i.e. any module from a non-pure-
Python
module distribution; otherwise, return the platform-shared
library
directory. If 'standard_lib' is true, return the directory
containing standard Python library modules; otherwise, return
the
directory for site-specific modules.

If 'prefix' is supplied, use it instead of sys.prefix or
sys.exec_prefix -- i.e., ignore 'plat_specific'.
 
D

Diez B. Roggisch

pythonewbie said:
pythonewbie schrieb:


pythonewbie schrieb:
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.


I doubt that you can say such things. You can even manipulate the path
at runtime.

And I still don't understand WHY you want that? If you want
site-packages, why don't you loop through the paths until you find it?

Diez
 
P

pythonewbie

pythonewbie schrieb:


pythonewbie schrieb:
pythonewbie schrieb:
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.

I doubt that you can say such things. You can even manipulate the path
at runtime.

And I still don't understand WHY you want that? If you want
site-packages, why don't you loop through the paths until you find it?

Diez

Because the solution using distutils.sysconfig.get_python_lib() is
very smart !
Cheers
 
J

John Machin

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 !"

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)])
[(0, ''),
(1, 'c:\\python25\\lib\\site-packages\\setuptools-0.6c3-py2.5.egg'),
(2, 'C:\\WINDOWS\\system32\\python25.zip'),
(3, 'c:\\python25\\DLLs'),
(4, 'c:\\python25\\lib'),
(5, 'c:\\python25\\lib\\plat-win'),
(6, 'c:\\python25\\lib\\lib-tk'),
(7, 'c:\\python25'),
(8, 'c:\\python25\\lib\\site-packages'),
(9, 'c:\\python25\\lib\\site-packages\\win32'),
(10, 'c:\\python25\\lib\\site-packages\\win32\\lib'),
(11, 'c:\\python25\\lib\\site-packages\\Pythonwin')]
Something like this might be more reliable:
.... m = re.match(r'(.*)[\\/][Ll]ib[\\/]site-packages$', p)
.... if m:
.... print m.group(1, 0)
.... break
.... else:
.... raise Exception('Huh?')
....
('c:\\python25', 'c:\\python25\\lib\\site-packages')
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
sys.path:

C:\junk>\python21\python
Python 2.1.3 (#35, Apr 8 2002, 17:47:50) [MSC 32 bit (Intel)] on
win32
Type "copyright", "credits" or "license" for more information.['', 'C:\\junk', 'C:\\python21\\DLLs', 'C:\\python21\\lib', 'C:\
\python21\\lib\\
plat-win', 'C:\\python21\\lib\\lib-tk', 'C:\\python21']
Before you rush out and re-invent the wheel, have a look at this:

http://www.python.org/community/sigs/current/distutils-sig/

You may like to re-ask your questions on the distutils mailing list.

HTH,
John
 
P

pythonewbie

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 !"

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)])

[(0, ''),
(1, 'c:\\python25\\lib\\site-packages\\setuptools-0.6c3-py2.5.egg'),
(2, 'C:\\WINDOWS\\system32\\python25.zip'),
(3, 'c:\\python25\\DLLs'),
(4, 'c:\\python25\\lib'),
(5, 'c:\\python25\\lib\\plat-win'),
(6, 'c:\\python25\\lib\\lib-tk'),
(7, 'c:\\python25'),
(8, 'c:\\python25\\lib\\site-packages'),
(9, 'c:\\python25\\lib\\site-packages\\win32'),
(10, 'c:\\python25\\lib\\site-packages\\win32\\lib'),
(11, 'c:\\python25\\lib\\site-packages\\Pythonwin')]



Something like this might be more reliable:

... m = re.match(r'(.*)[\\/][Ll]ib[\\/]site-packages$', p)
... if m:
... print m.group(1, 0)
... break
... else:
... raise Exception('Huh?')
...
('c:\\python25', 'c:\\python25\\lib\\site-packages')


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
sys.path:

C:\junk>\python21\python
Python 2.1.3 (#35, Apr 8 2002, 17:47:50) [MSC 32 bit (Intel)] on
win32
Type "copyright", "credits" or "license" for more information.>>> import sys; sys.path

['', 'C:\\junk', 'C:\\python21\\DLLs', 'C:\\python21\\lib', 'C:\
\python21\\lib\\
plat-win', 'C:\\python21\\lib\\lib-tk', 'C:\\python21']



Before you rush out and re-invent the wheel, have a look at this:

http://www.python.org/community/sigs/current/distutils-sig/

You may like to re-ask your questions on the distutils mailing list.

HTH,
John

Hi John,

Thanks for your help and suggestions.

Your code is very interesting for the newbie that I am.

But I have not understood your two last suggestions...

As a newbie, I have asked usenet for help in order to get a easy/
convenient way to get the site-packages directory, and the best reply
I obtained, was to use the function
distutils.sysconfig.get_python_lib().

This function is a really good way to avoid to re-invent the wheel to
get what I wanted !

Cheers.
 
J

John Machin

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 !"
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)])
[(0, ''),
(1, 'c:\\python25\\lib\\site-packages\\setuptools-0.6c3-py2.5.egg'),
(2, 'C:\\WINDOWS\\system32\\python25.zip'),
(3, 'c:\\python25\\DLLs'),
(4, 'c:\\python25\\lib'),
(5, 'c:\\python25\\lib\\plat-win'),
(6, 'c:\\python25\\lib\\lib-tk'),
(7, 'c:\\python25'),
(8, 'c:\\python25\\lib\\site-packages'),
(9, 'c:\\python25\\lib\\site-packages\\win32'),
(10, 'c:\\python25\\lib\\site-packages\\win32\\lib'),
(11, 'c:\\python25\\lib\\site-packages\\Pythonwin')]
Something like this might be more reliable:
... m = re.match(r'(.*)[\\/][Ll]ib[\\/]site-packages$', p)
... if m:
... print m.group(1, 0)
... break
... else:
... raise Exception('Huh?')
...
('c:\\python25', 'c:\\python25\\lib\\site-packages')
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
sys.path:
C:\junk>\python21\python
Python 2.1.3 (#35, Apr 8 2002, 17:47:50) [MSC 32 bit (Intel)] on
win32
Type "copyright", "credits" or "license" for more information.>>> import sys; sys.path
['', 'C:\\junk', 'C:\\python21\\DLLs', 'C:\\python21\\lib', 'C:\
\python21\\lib\\
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.
HTH,
John

Hi John,

Thanks for your help and suggestions.

Your code is very interesting for the newbie that I am.

But I have not understood your two last suggestions...

As a newbie, I have asked usenet for help in order to get a easy/
convenient way to get the site-packages directory, and the best reply
I obtained, was to use the function
distutils.sysconfig.get_python_lib().

This function is a really good way to avoid to re-invent the wheel to
get what I wanted !

I am talking about your underlying goal "My goal is to verify if an/
several extension(s) are installed and to automatically install the
missing ones on Linux or Win32." ... you may well find that there is
at least one wheel for "automatically install".
 
D

Dennis Lee Bieber

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']
'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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
P

pythonewbie

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']

'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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
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
 
P

pythonewbie

@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']

'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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
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 :
.... 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?

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

-

Thanks for your advice to read : http://www.python.org/community/sigs/current/distutils-sig/

Cheers
 
J

John Machin

@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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
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.

Hi John Machin,

Your code :

... 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.
 
D

Diez B. Roggisch

pythonewbie
Because the solution using distutils.sysconfig.get_python_lib() is
very smart !

Depending on your goal. You said

"""
My goal is to verify if an/several extension(s) are installed and to
automatically install the missing ones on Linux or Win32.
"""

This goal can't be reached with only the site-packages - because I can
install packages somewhere else (matter of factly, this happens on debian
for example, they've split the install-dirs and created a bunch of dirs
under /usr/share)

So having a method that gives you the installation root doesn't help much
here.

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top