473,382 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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.
Jan 20 '08 #1
9 2072
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

Jan 20 '08 #2
On 20 jan, 12:20, Christian Heimes <li...@cheimes.dewrote:
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 ?
Jan 20 '08 #3
pythonewbie schrieb:
On 20 jan, 12:20, Christian Heimes <li...@cheimes.dewrote:
>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
Jan 20 '08 #4
On 20 jan, 19:50, "Diez B. Roggisch" <de...@nospam.web.dewrote:
pythonewbie schrieb:
On 20 jan, 12:20, Christian Heimes <li...@cheimes.dewrote:
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.
Jan 20 '08 #5
pythonewbie wrote:
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.

>
Cheers.
Jan 20 '08 #6
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
Jan 20 '08 #7
On 20 jan, 23:19, "Martin v. Löwis" <mar...@v.loewis.dewrote:
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
http://forum.ubuntu-fr.org/viewtopic.php?id=184199
>>import distutils.sysconfig
distutils.sysconfig.get_python_lib()
'/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'.
Jan 20 '08 #8
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
Jan 21 '08 #9
On 21 jan, 10:34, "Diez B. Roggisch" <de...@nospam.web.dewrote:
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
To John Machin,
>>sys.path
['', '/usr/lib/python25.zip', '/usr/lib/python2.5', '/usr/lib/
python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/
python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/
usr/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages/
Numeric', '/usr/lib/python2.5/site-packages/gst-0.10', '/var/lib/
python-support/python2.5', '/usr/lib/python2.5/site-packages/gtk-2.0',
'/var/lib/python-support/python2.5/gtk-2.0', '/usr/lib/python2.5/site-
packages/wx-2.8-gtk2-unicode']
Jan 21 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Alberto Vera | last post by:
Hello: I have installed WIN32 extensions over Windows2003 server standard edition and when I restarted this I found mistakes on it. Is it compatible Win2003 with Python 2.2.3 Win32 extensions?...
0
by: John Hunter | last post by:
I'm using mingw to build python extensions. To ensure maximum portability across windows platforms (98, ME, NT, XP) is it a good idea to build on a lowest common denominator system, eg, 98, or...
0
by: Ishwor | last post by:
Hello all, I was looking through Mark Hammond's website for win32 extensions for Python 2.4 but couldn't find it. If i am not wrong has anyone any idea when it will be available or is it being...
1
by: Srijit Kumar Bhadra | last post by:
Hello, I see that it is possible to use mmapfile.pyd of win32all. The same is mentioned in http://www.python.org/windows/win32/#mmapfile. Unfortunately I could not trace any example using...
1
by: Matthew | last post by:
Hi: I recently installed Python 2.4 and the Win 32 extensions on Windows XP. I had some problems with the COM makepy utility for the Excel COM libraries. I reported this problem to the...
3
by: Mudcat | last post by:
Howdy, I could have sworn I downloaded a version of python win that supported object library 11.0 at some point. However I just downloaded versions 204 and 203, and the highest version they have...
4
by: news | last post by:
I've just started to test/learn python. I've got Linux > mandrake9 > python & documentation. What I'll initially want to be doing needs file I/O, so I wanted to confirm file I/O early in my...
0
by: mario.danic | last post by:
Hello, If there is anyone familiar with python C api, and would like to get involved with writing python extensions for above two libs (http://libburn.pykix.org) please contact me. Kind...
3
by: SteveD | last post by:
Hi guys, http://luaforge.net/frs/?group_id=327 pgdb.zip is an addition to scite-debug, which adds source debugging to the popular SciTE programmer's editor. gdbpy.zip is a standalone version...
16
by: inhahe | last post by:
Can anyone give me pointers/instructions/a template for writing a Python extension in assembly (or better, HLA)?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.