473,473 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Idea: PYTHONPATH_VER

I've been working on systems that have multiple versions of python.
People are also trying to manage the compilation of external extension
modules. The problem is there is no easy way to control the separate
modules for each python version.

I keep thinking having a separate PYTHONPATH environment variable for
each version of Python would really make life easier. I have heard Perl
started doing this sometime ago and it is in use on these same machines.

At startup Python 2.4 would prepend PYTHONPATH24 to the regular path.
Easy to do, likely just slip into the "site.py". Would there be any
problems trying to get something like this added for 2.4?
Jul 18 '05 #1
7 1198
Pete Shinners wrote:
I've been working on systems that have multiple versions of python.
People are also trying to manage the compilation of external extension
modules. The problem is there is no easy way to control the separate
modules for each python version.

I keep thinking having a separate PYTHONPATH environment variable for
each version of Python would really make life easier. I have heard Perl
started doing this sometime ago and it is in use on these same machines.


I'm not entirely clear on the need for all this version stuff
people keep talking about, but wouldn't the effect of the above
be about the same as using a .pth file in the appropriate place
for each different Python version on your machine? Then you
can pick up different versions of different things at will
depending on which version of Python is run.

Having missed the discussion preceding, I'm probably off the mark,
but in my experience just about everything that can be solved with
PYTHONPATH can be handled with a .pth file as well, and I haven't
had any need to use PYTHONPATH for quite some time as a result.

-Peter
Jul 18 '05 #2
Peter Hansen wrote:
Having missed the discussion preceding, I'm probably off the mark,
but in my experience just about everything that can be solved with
PYTHONPATH can be handled with a .pth file as well, and I haven't
had any need to use PYTHONPATH for quite some time as a result.


How do you handle the fact that .pth files are only read from certain places,
and not others? This problem has me currently rather stuck with gross hacks:
packages like Numeric, which rely on a .pth file instead of being a 'true'
python package (with __init__.py), are very problematic. I am trying to share
Numeric from an NFS mounted directory for multiple clients, located
at /usr/local/lib/python. It was installed there via 'setup.py install
--home=/usr/local'. The problem is that python does NOT scan this directory
for .pth files, even if it is listed in PYTHONPATH. .pth files only have an
effect for directories in sys.prefix, I think.

I have actually come to HATE with a vengeance packages which rely on .pth files,
because of this behavior of python of not including them for anything in
PYTHONPATH. So I would really appreciate pointers from someone who has
successfully solved this, since it's quite likely that I'm just misusing the
system.

Thanks in advance,

Fernando
Jul 18 '05 #3
Fernando Perez wrote:
Peter Hansen wrote:
Having missed the discussion preceding, I'm probably off the mark,
but in my experience just about everything that can be solved with
PYTHONPATH can be handled with a .pth file as well, and I haven't
had any need to use PYTHONPATH for quite some time as a result.
How do you handle the fact that .pth files are only read from certain places,
and not others? This problem has me currently rather stuck with gross hacks:


I confess to never having had any particular troubles with it, other
than in trying to use it for adding special other directories during
unit testing, where I had to do "import site; site.addsitedir('.')"
or something close to that at the top of my xxx_test.py file.
packages like Numeric, which rely on a .pth file instead of being a 'true'
python package (with __init__.py), are very problematic.
Sorry, haven't used it.
--home=/usr/local'. The problem is that python does NOT scan this directory
for .pth files, even if it is listed in PYTHONPATH. .pth files only have an
effect for directories in sys.prefix, I think.
Actually, I believe it's recursive, in that any directories added during
..pth processing are themselves scanned for .pth files and the new ones
added, and so on.
I have actually come to HATE with a vengeance packages which rely on .pth files,
because of this behavior of python of not including them for anything in
PYTHONPATH. So I would really appreciate pointers from someone who has
successfully solved this, since it's quite likely that I'm just misusing the
system.


I'm not sure I've seen a package which *relied* on it, except for
pywin32, and it seems to work very nicely and the .pth file (which
I just had to verify is still there) is pretty much invisible.

I might have some better idea how to deal with it if I'd ever had
trouble with it. One thing to note: I do most development on Windows.
Perhaps, for some reason, the problems are lesser there. (Which would
be a little surprising, but given Linux' issues with installing
software, perhaps not entirely unlikely.)

-Peter
Jul 18 '05 #4
Peter Hansen wrote:
Fernando Perez wrote:
Peter Hansen wrote:
Having missed the discussion preceding, I'm probably off the mark,
but in my experience just about everything that can be solved with
PYTHONPATH can be handled with a .pth file as well, and I haven't
had any need to use PYTHONPATH for quite some time as a result.
How do you handle the fact that .pth files are only read from certain places,
and not others? This problem has me currently rather stuck with gross hacks:


[snip] I might have some better idea how to deal with it if I'd ever had
trouble with it. One thing to note: I do most development on Windows.
Perhaps, for some reason, the problems are lesser there. (Which would
be a little surprising, but given Linux' issues with installing
software, perhaps not entirely unlikely.)


Thanks, Peter. I might start a separate thread asking about this, with a
clearer description of my problem. I don't think it's a linux issue, but
rather one of dealing with when python loads (or not) .pth files. As I said,
it may well just be my misunderstanding of how the system really works.

Regards,

Fernando
Jul 18 '05 #5
Fernando Perez wrote:
Thanks, Peter. I might start a separate thread asking about this, with a
clearer description of my problem. I don't think it's a linux issue, but
rather one of dealing with when python loads (or not) .pth files. As I said,
it may well just be my misunderstanding of how the system really works.


Check the source in site.py first, then, as it is fairly straight-
forward about what it does.

-Peter
Jul 18 '05 #6
Peter Hansen wrote:
Check the source in site.py first, then, as it is fairly straight-
forward about what it does.


Thanks for the pointer, I didn't know what part of python was responsible for
these manipulations. Knowing where to look, it will be much easier now to deal
with this issue.

Regards,

Fernando
Jul 18 '05 #7
At some point, Fernando Perez <fp*******@yahoo.com> wrote:
Peter Hansen wrote:
Having missed the discussion preceding, I'm probably off the mark,
but in my experience just about everything that can be solved with
PYTHONPATH can be handled with a .pth file as well, and I haven't
had any need to use PYTHONPATH for quite some time as a result.
How do you handle the fact that .pth files are only read from certain places,
and not others? This problem has me currently rather stuck with gross hacks:
packages like Numeric, which rely on a .pth file instead of being a 'true'
python package (with __init__.py), are very problematic. I am trying to share
Numeric from an NFS mounted directory for multiple clients, located
at /usr/local/lib/python. It was installed there via 'setup.py install
--home=/usr/local'. The problem is that python does NOT scan this directory
for .pth files, even if it is listed in PYTHONPATH. .pth files only have an
effect for directories in sys.prefix, I think.


Debian uses the following patch to site.py to look in /usr/local also:

--- /usr/lib/python2.3/site.py 2004-05-13 15:55:47.000000000 -0400
+++ Lib/site.py 2004-03-30 20:46:01.000000000 -0500
@@ -161,10 +156,10 @@
if reset:
_dirs_in_sys_path = None

-prefixes = [os.path.join(sys.prefix, "local"), sys.prefix]
+prefixes = [sys.prefix]
sitedir = None # make sure sitedir is initialized because of later 'del'
if sys.exec_prefix != sys.prefix:

You can also make a sitecustomize.py that does the adding of the
various directories (it's imported at the end of site.py).

## sitecustomize.py
import site
site.addsitedir('/usr/local')
I have actually come to HATE with a vengeance packages which rely on .pth files,
because of this behavior of python of not including them for anything in
PYTHONPATH. So I would really appreciate pointers from someone who has
successfully solved this, since it's quite likely that I'm just misusing the
system.


Bleh, yes. .pth files are mostly a hack for packages that *should be*
actual Python packages.

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
Jul 18 '05 #8

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

Similar topics

14
by: Daniel Chartier | last post by:
Hello. I work in the paper industry and we recently had someone (the original author) from within the company make a program for preventive maintenance. However, it had some bugs and we wanted...
34
by: SeeBelow | last post by:
I see the value of a class when two or more instances will be created, but Python programmers regularly use a class when there will only be one instance. What is the benefit of this? It has a...
7
by: winlinchu | last post by:
Hi! I use Python, and writing some extension modules I think which could be written an C compiler, useful only to compile extension modules (I not think an GCC!!!!), so that the user not have to...
4
by: Luca | last post by:
Hello Everybody, I'm a 26 years old Italian "Florentine" Computer technician :) I'm writing you about an idea that I've got of a function that could be introduced in new web browsers (or even...
1
by: Lipei | last post by:
I have once try IntelliJ IDEA.And I can refactor easily,I can add try and catch just by a few clicks.It also can help me analazy the program's error.(e.g It warned me that I did't initialize the...
4
by: Jordan Marton | last post by:
Hi, I spent the entire weekend struggling to find a suitable tempalte solution for my site. Yes, user controls were good, but I needed one page that could control user controls on each adn every...
12
by: Paul H | last post by:
A little off topic this one because the database may not be written in Access. I am just looking for some advice.. I have an idea to help prevent a particular type of crime, a database will be...
28
by: onkar | last post by:
This idea might be vey crazy. But I hope to get answers to this .. from comp.lang.c If a compiler is designed such that it automatically adds a free() matching every malloc() then is it not a...
2
by: pigeonrandle | last post by:
Hi, My application creates a project that is structured like a tree, so i want to use a treeview to display it to the user. Would it be a good idea to create the various parts of project as...
0
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...
0
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,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
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...
0
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 ...
0
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...

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.