Archived

This topic is now archived and is closed to further replies.

Kylotan

Resolving conflicting paths to different versions

Recommended Posts

I just installed Python 2.3 on my Mandrake 9.0 box by compiling from source. It went into /usr/local, but the old install of 2.2.3 is in /usr. /usr takes precedence in my path, so not only do I get the wrong version of Python if I don''t type the full path, I get lots of errors when I try and run Python 2.3 stuff because it just uses the first Python libraries it finds. I couldn''t see a practical way to uninstall Python 2.2.3 beforehand as it came in RPM form and that would have asked me to uninstall numerous other Python-dependent packages. I couldn''t upgrade the RPM as I don''t have Python 2.3 in an RPM, and it may be some time before such an RPM is available for my system, if indeed it ever is. I would just drop a symbolic link in /usr/bin to the new Python, except there''s already a small stub executable in there for the old one which I am loathe to delete without knowing more first. Also I doubt this would result in it resolving the right libraries. I don''t know how many changes it would require to get this done properly. Finally, I''m not sure whether changing my path order to favour /usr/local/ over /usr would be wise, but maybe that''s the easiest answer when it comes to me needing to upgrade system components. Anybody got any ideas on the best way to progress with this? [ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

Share this post


Link to post
Share on other sites
I'm talking as an uneducated newbie, but...

I don't recall how RPMs work and you've probably already thought of this anyway, but just in case... If uninsalling Python 2.2.3 will it automatically uninstall the python dependant things, or will it ask? (i.e. if it asks, just say no!)

Anyway python has a pythonpath, which should be a $PYTHONPATH envvar... In theory you have one already that is pointing to your python 2.2.3 directories.

So, all you should need to do is change $PYTHONPATH to point to your /usr/local/python/ and then make a symlink to the python interperter in /usr/.. just back up the existing one that is there first, just in case


Regarding the "#! /usr/bin/env python" lines in python files, I don't how how that works but perhaps that would need to be updated as well.


But as I said, I'm mostly just guessing here.

:Luck!
Feral
*edit: clarification, reformatting for readability and that sort of thing*

[edited by - FeralofFireTop on August 7, 2003 8:17:17 AM]

Share this post


Link to post
Share on other sites
I seem to recall that the rpm manager will say "the following packages will need to be uninstalled... [long list]... continue? y/n".

I have no idea how to set an environment variable for all users. Assuming I found that out then, does Python find all the library stuff from that? In other words, I only have to ensure it can find the existing executable?

No idea what to do about various system scripts that use Python, but I''d hope I can make them use the new Python version (via a symlink) without breaking anything.

Share this post


Link to post
Share on other sites
"the following packages will need to be uninstalled... [long list]... continue? y/n". ... says to me that it''s up to you to uninstall them; which is perfect, don''t uninstall them

I know you have to export an envvar (say from .bashrc .. I think .. or the like )... I''m not sure for all users, I''d say there should be some facility for that though.


As I understand it, yes python uses it''s own internal search path (of which $PYTHONPATH is a part) to find it''s parts.

So, yes all you should need is $PYTHONPATH set to your new python directory and a symlink in /usr that points to the new executable.


I think. (=
I''m going to go look in mandrak8 and see what I find. (I''m going to format and put FreeBSD on in a few so I''ll see what damage uninstalling python does to the things that use it.)

Share this post


Link to post
Share on other sites
Ok, well I found out I didn''t have $PYTHONPATH nor any other envvars that I could find related to python.

I don''t know how the python executable was finding the libs.

Anyway to make a long story short, looks like $PYTHONPATH can be used to override the default search path, perhaps you can set and export it in `/etc/profile` which seems (on mandrake8 anwyay) where global env vars should be set, I say that because:

quote:
/etc/bashrc had this in it:
# System wide functions and aliases
#
# Environment stuff goes in /etc/profile



Also, I used `Software Manager` under KDE to uninstall python, it did that and took the dependances with it. ... Just to be clear, the depandances were uninstalled too. (to it''s credit, it did say it would )





Gory details follow...




quote:
whereis python
[root@A900 etc]# whereis python
python: /usr/bin/python /usr/lib/python2.1 /usr/include/python2.1 /usr/share/man/man1/python.1.bz2



I also cp ed /usr/bin/python to /usr/, it functioned the same.

quote:
Where python itself says it''s libs are:
[feral@A900 feral]$ python
Python 2.1.1 (#1, Aug 30 2001, 17:36:05)
[GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.61mdk)] on linux-i386
Type "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['''', ''/usr/lib/python2.1'', ''/usr/lib/python2.1/plat-linux-i386'', ''/usr/lib/python2.1/lib-tk'', ''/usr/lib/python2.1/lib-dynload'', ''/usr/lib/python2.1/site-packages'', ''/usr/lib/python2.1/site-packages/Numeric'', ''/usr/lib/python2.1/site-packages/PIL'']
>>>
quote:
For ease of viewing:
[
''''
''/usr/lib/python2.1''
''/usr/lib/python2.1/plat-linux-i386''
''/usr/lib/python2.1/lib-tk''
''/usr/lib/python2.1/lib-dynload''
''/usr/lib/python2.1/site-packages''
''/usr/lib/python2.1/site-packages/Numeric''
''/usr/lib/python2.1/site-packages/PIL''
]




(sys, as you may well know, is a built in module, meaning it''s part of the executable, unless I am mistaken)


So, `/usr/lib/python2.1` is where all the libs were located.


quote:
python -h that:
Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
PYTHONPATH : '':''-separated list of directories prefixed to the
default module search path. The result is sys.path.
PYTHONHOME : alternate directory (or :).
The default module search path uses /python2.1.
PYTHONCASEOK : ignore case in ''import'' statements (Windows).



So, it should be getting it''s information from $PATH then, $PATH is
quote:

[feral@A900 feral]$ echo $PATH
/usr//bin:/bin:/usr/bin::/usr/local/bin:/usr/X11R6/bin:/usr/games:/home/feral/bin
[feral@A900 feral]$
quote:
For ease of viewing:
/usr//bin
/bin
/usr/bin
/usr/local/bin
/usr/X11R6/bin
/usr/games
/home/feral/bin





This is where I started to get confused. no /usr/lib/ entry. (as I understand it PYTHONHOME (defaulting to `/python2.1` should be appended to the path entries.) ... As I think /usr/lib/python2.1/ is where the files are I expected a /usr/lib/ entry, it plus PYTHONHOME would have been /usr/lib/python2.1/. BUT I didn''t find that!


I''m assuming there was some file that was telling it libs where in lib or something. I''m really not sure.


Of course, this does not mean I know what I am talking about either (:

Hope this helps

Share this post


Link to post
Share on other sites
I think it can deduce the default lib directory from the location of the Python executable. The docs talk about a "built-in default" if you have no Pythonpath var. I think it''s just the Python dir, plus the current working dir, and the system path.

I made a backup of the old Python file and put in a symbolic link to the new one, and that seems to work fine. I had to do something similar for IDLE though (the IDE) as that was running via a script in /usr/bin. I just commented out the old line and edited the script to point at the new idle.py file. That''s working fine so far, but I''ve not managed to put it under any serious stress yet.

Thanks for the advice so far.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

Share this post


Link to post
Share on other sites
Why not just reconfigure to install to /usr instead of /usr/local?

% ./configure --prefix=/usr

Then it will just overwrite everything.

Share this post


Link to post
Share on other sites
What worries me about that is that if any important scripts rely on 2.2 (which seems unreasonable, but is still possible), they might get broken in the process. I prefer things to go in /usr/local too, although I suppose it''s debatable when you''re overwriting basic system languages.

Share this post


Link to post
Share on other sites
DON'T delete the old version, things probably won't break, but you never know. There IS a new keyword ('yield'), and that could screw up some old scripts.

Put /usr/local before /usr in your path, so programs you install will always have precedence over programs that came with your distro.

On my distro (slack 9), /usr/local/bin/python is a symlink to /usr/local/python/python23 (or something like that). It would surprise me if mandrake isn't the same, but if it isn't, maybe you should simply 'mv /usr/bin/python /usr/bin/python22' and 'mv /usr/local/bin/python /usr/local/bin/python23' and finally 'ln -s /usr/local/bin/python23 /usr/local/bin/python'.

Of course you need to reinstall any site-packages for python23.

HTH,
Dustin

edit: spelling

[edited by - thedustbustr on August 8, 2003 2:29:09 PM]

Share this post


Link to post
Share on other sites
By the way, you probably shouldn''t edit /etc/profile. Edit ~/.profile (or ~/.bash_profile or something similar). That way, if you break something, its only you who is affected.

Share this post


Link to post
Share on other sites
If you compile something on Linux, usually there is an "uninstall" target, too. So you could try "make uninstall" in the source directory and see what happens.

Then you could experiment with "./configure --prefix=/usr --sysconfdir=/etc && make && make install" thingy.

Good luck!

--
Bernie Kirschner
www.bkgames.com

Share this post


Link to post
Share on other sites
So... putting /usr/local above /usr in the priority is good, but I shouldn''t do it for root, right?

I think what confuses me is the little stub executable in /usr/bin, called ''python'' but it''s obviously not the actual python executable as it''s only 9kb in size. I just backed that up and replaced it with a symlink to /usr/local/python for now, and things seem to be working, but I expect a proper path change will be advisable, if I can work out how to do it properly There''s some trickery in one of the scripts I was looking at that puts /usr/games into my path if I''m a user above 500... I need that to use usr/local/games too, so I guess I can kill 2 birds with one stone. I get the impression these Mandrake people don''t expect you to install much new software, if they''re expecting everying in /usr and not /usr/local.

Anyway, I''m basically hoping that at some point, I''ll be able to get an RPM for Python 2.3, which will then upgrade my 2.2 install ''officially''.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

Share this post


Link to post
Share on other sites