473,897 Members | 2,819 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 2108
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
1269
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
969
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
1039
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
3094
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
1697
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
1821
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
3437
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
1052
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
2249
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
1580
by: inhahe | last post by:
Can anyone give me pointers/instructions/a template for writing a Python extension in assembly (or better, HLA)?
0
9990
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9837
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11250
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
10476
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
9655
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...
1
8031
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7183
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();...
2
4292
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3299
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.