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 Code:
export PATH=$PATH:$HOME/usr/bin Code:
$which python Thanks in advance! Cheers, Guru |
You can simply use the full pathname.....
|
Change the export line:
Code:
export PATH=$HOME/usr/bin:$PATH edit: There is a possibility this will break some things. |
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 Code:
alias my_phyton='$HOME/usr/bin/python' |
Quote:
|
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! |
Quote:
Code:
bash-3.1$ ls -l /usr/bin/python* |
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. |
Quote:
Code:
$ls-l $HOME/usr/bin/ Cheers, Guru |
Code:
-rwxr-xr-x 2 user 3651483 2009-01-12 19:41 python (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. |
On a machine running CentOS 5.2 I have
Code:
$ ls -il /usr/bin/python* |
Seemingly Slackware has only symlinks (softlinks):
Code:
pwc101@linux:~> ls -il /usr/bin/python* |
All times are GMT -5. The time now is 07:47 PM. |