LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-14-2009, 06:57 AM   #1
prasadbrg
LQ Newbie
 
Registered: Nov 2003
Posts: 27

Rep: Reputation: 15
Two executables with same name in $PATH: How do I force the right one to be used?


Hello everyone,
I just installed Python 2.6 on a system where I don't have root access. The system previously had Python 2.2 installed on it. While compiling from source, I used the
Code:
--prefix=$HOME/usr
option. So now I have a 'python' executable in $HOME/usr/bin, which runs Python 2.6. I added an
Code:
 export PATH=$PATH:$HOME/usr/bin
line to my $HOME/.bashrc file and did 'source .bashrc'. Now 'echo $PATH' shows '$HOME/usr/bin' at the end. Still, the 'python' command brings up the old Python 2.6:
Code:
$which python
/usr/bin/python
How do I force the 'python' command to point to the Python 2.6 executable in '$HOME/usr/bin'?

Thanks in advance!
Cheers,
Guru
 
Old 01-14-2009, 07:01 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
You can simply use the full pathname.....
 
Old 01-14-2009, 07:05 AM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Change the export line:
Code:
export PATH=$HOME/usr/bin:$PATH
so it sees your $HOME/usr/bin before the rest of the path.

edit: There is a possibility this will break some things.

Last edited by pwc101; 01-14-2009 at 07:06 AM.
 
Old 01-14-2009, 07:06 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,506

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
The rule is: if two executables have the same name, the first one encountered through the path is executed. So you can just invert the assignment:
Code:
export PATH=$HOME/usr/bin:$PATH
or - better - create an alias to the executable specifying its absolute path (as suggested by pixellany). For example
Code:
alias my_phyton='$HOME/usr/bin/python'
Edit: pwc101 beat me!

Last edited by colucix; 01-14-2009 at 07:07 AM.
 
Old 01-14-2009, 07:17 AM   #5
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by colucix View Post
Edit: pwc101 beat me!
First time for everything, colucix!
 
Old 01-14-2009, 07:35 AM   #6
prasadbrg
LQ Newbie
 
Registered: Nov 2003
Posts: 27

Original Poster
Rep: Reputation: 15
Thumbs up Works!

Thanks, everyone, for the prompt replies!
pixellany, using the full path is what I've been doing so far... I was worried that some script or program that I might use would call 'python' and it would use the wrong one... for the same reason, did not use the alias (in fact, there is also a 'python2.6' executable in $HOME/usr/bin, which works fine).
I did not know about the path order rule. I inverted the assignment as suggested, and 'which python' now reveals the right one.
Thanks once again, everyone!
Cheers,

Guru

P.S. It's nice to have people racing to solve your problems - this is truly a wonderful forum!

Last edited by prasadbrg; 01-14-2009 at 07:38 AM. Reason: grammar
 
Old 01-14-2009, 07:55 AM   #7
GazL
Senior Member
 
Registered: May 2008
Posts: 3,392

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by prasadbrg View Post
(in fact, there is also a 'python2.6' executable in $HOME/usr/bin, which works fine).
You'll probably find that python is a symbolic link to python2.6. At least that's how it's installed on my slackware box.

Code:
bash-3.1$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root    9 2008-12-05 12:26 /usr/bin/python -> python2.5
lrwxrwxrwx 1 root root   16 2008-12-05 12:26 /usr/bin/python-config -> python2.5-config
-rwxr-xr-x 1 root root 3320 2008-09-11 19:44 /usr/bin/python2.5
-rwxr-xr-x 1 root root 1418 2008-09-11 19:43 /usr/bin/python2.5-config
 
Old 01-14-2009, 08:21 AM   #8
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,378

Rep: Reputation: 1109Reputation: 1109Reputation: 1109Reputation: 1109Reputation: 1109Reputation: 1109Reputation: 1109Reputation: 1109Reputation: 1109
You can even go one step further...

PATH=my/path/this/time python blah

This is a one-time declaration of the symbol "PATH," known only to this instance of (say...) Python and any of its descendents. It supersedes any exported version of that same symbol, and only in this very-specific context.
 
Old 01-14-2009, 10:33 AM   #9
prasadbrg
LQ Newbie
 
Registered: Nov 2003
Posts: 27

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by GazL View Post
You'll probably find that python is a symbolic link to python2.6. At least that's how it's installed on my slackware box.
Gazl, that's what I thought too, at first. I was surprised to see this:
Code:
$ls-l  $HOME/usr/bin/
total 7184
-rwxr-xr-x  1 user     125 2009-01-12 19:27 2to3
-rwxr-xr-x  1 user     672 2009-01-13 23:19 f2py
-rwxr-xr-x  1 user     675 2009-01-12 22:14 f2py2.6
-rwxr-xr-x  1 user     113 2009-01-12 19:27 idle
-rwxr-xr-x  1 user      69 2009-01-13 23:27 nosetests
-rwxr-xr-x  1 user      98 2009-01-12 19:27 pydoc
-rwxr-xr-x  2 user 3651483 2009-01-12 19:41 python
-rwxr-xr-x  2 user 3651483 2009-01-12 19:41 python2.6
-rwxr-xr-x  1 user    1438 2009-01-12 19:42 python2.6-config
lrwxrwxrwx  1 user      16 2009-01-12 19:42 python-config -> python2.6-config
-rwxr-xr-x  1 user   18068 2009-01-12 19:27 smtpd.py
sundialsvcs, my apprehension was more about calls to python from scripts, or other programs that I intend to use, which I haven't written. To be honest, I don't have any solid grounds for this apprehension - while I intend to use code that makes calls to python, I'm not sure whether such calls would go through the executable itself (I'm a newbie to these things!). On the other hand, executable python scripts do have this line at the beginning: '#!/usr/bin/env python'. I just wanted to be doubly sure, that all subsequent programs that I run as user, as a rule use the new Python 2.6 executable.
Cheers,
Guru
 
Old 01-14-2009, 11:32 AM   #10
GazL
Senior Member
 
Registered: May 2008
Posts: 3,392

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Code:
-rwxr-xr-x  2 user 3651483 2009-01-12 19:41 python
-rwxr-xr-x  2 user 3651483 2009-01-12 19:41 python2.6
Ahhhh, what you seem to have there is a hardlink. Note the '2'.
(I guess whoever packaged it or did the make file forgot the '-s' on the ln command). I don't know if this is the norm with python installs or not.

To confirm that is what has happened you can do a ls -i on both and see if it returns the same inode value, but I'm fairly sure that's it.

Interestingly, the python-config command uses symbolics as expected.

Last edited by GazL; 01-14-2009 at 11:33 AM.
 
Old 01-14-2009, 12:04 PM   #11
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,506

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
On a machine running CentOS 5.2 I have
Code:
$ ls -il /usr/bin/python*
487364 -rwxr-xr-x 2 root root 5632 May 24  2008 /usr/bin/python
487220 lrwxrwxrwx 1 root root    6 Oct  7 17:40 /usr/bin/python2 -> python
487364 -rwxr-xr-x 2 root root 5632 May 24  2008 /usr/bin/python2.4
this confirms the hard link issue. All the three items were installed by the python RPM. Idem in Fedora. On the contrary, on a OpenSuse system the situation is similar to that reported by GazL for Slackware.
 
Old 01-14-2009, 12:09 PM   #12
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Seemingly Slackware has only symlinks (softlinks):
Code:
pwc101@linux:~> ls -il /usr/bin/python*
98765 lrwxrwxrwx 1 root root    9 2009-01-05 20:24 /usr/bin/python -> python2.5
98762 lrwxrwxrwx 1 root root   16 2009-01-05 20:24 /usr/bin/python-config -> python2.5-config
98759 -rwxr-xr-x 1 root root 3320 2008-09-11 19:44 /usr/bin/python2.5
98761 -rwxr-xr-x 1 root root 1418 2008-09-11 19:43 /usr/bin/python2.5-config
 
  


Reply

Tags
conflict, executable, name, path


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
set up java_home path in /home/user/.bashrc but use path in /usr/lib/java vitalstrike82 Slackware 4 01-13-2009 11:25 PM
How to force preferred library search path for Apache Larry James Linux - Server 7 03-04-2008 02:15 PM
emacs lisp problem, how to force to add " to path parv Linux - Software 8 03-07-2007 05:22 PM
./configure: how can I force PATH? palanca Linux - Newbie 1 07-21-2005 03:07 PM
Setting the path for sbin executables sdb6753 Linux - Software 1 11-23-2002 06:20 AM


All times are GMT -5. The time now is 05:59 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration