473,785 Members | 2,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2099
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.w eb.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_inf o).

HTH,
Martin
Jan 20 '08 #7
On 20 jan, 23:19, "Martin v. Löwis" <mar...@v.loewi s.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_inf o).

HTH,
Martin
http://forum.ubuntu-fr.org/viewtopic.php?id=184199
>>import distutils.sysco nfig
distutils.sys config.get_pyth on_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.sysco nfig.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.w eb.dewrote:
pythonewbie
Because the solution using distutils.sysco nfig.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
1262
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? Do you have any suggestion? Thanks
0
965
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 should it not matter? I'm worried, for example, that windows ME might have a funny system library that end up in the pyd and other systems will fail to link. John Hunter
0
1032
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 worked on? The activestate's version of Python has win32 extension but i won't be bothered to download it. :) -- cheers, Ishwor Gurung
1
3085
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 mmapfile. Any example or link to an example will be of help. I am interested to learn how to achieve efficient sharing of data between separate processes using mmapfile.
1
1691
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 sourceforge bug tracker. My question is , is python 2.3 and the win32 extensions more stable than Python 2.4?
3
1814
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 is OL 9.0. Does anyone know if this is a mistake or if Excel 2003 isn't yet supported with the extensions? Thanks,
4
3433
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 tests. Following the examples : >>> f=open('/tmp/workfile', 'w') >>> print f <open file '/tmp/workfile', mode 'w' at 80a0960> <-- OK
0
1045
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 regards, Mario
3
2233
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 which can be run from Emacs. These allow you to single-step from Python to C code in a debugger session.
16
1574
by: inhahe | last post by:
Can anyone give me pointers/instructions/a template for writing a Python extension in assembly (or better, HLA)?
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9949
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.