472,960 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 software developers and data experts.

Python version changes, sys.executable does not

Hello All,

I have two python versions installed, one in /usr/bin, and one in
/usr/local/bin. However, when invoking python without a full path,
I get the wrong executable with the right sys.executable string!
----------------------------------------------------------------------------
[root@M1 ~]# ls -l /usr/local/bin/python*
-rwxr-xr-x 2 root root 3783810 Jul 19 09:15 /usr/local/bin/python
-rwxr-xr-x 2 root root 3783810 Jul 19 09:15 /usr/local/bin/python2.5
-rwxr-xr-x 1 root root 1281 Jul 19 09:16 /usr/local/bin/python2.5-config
lrwxrwxrwx 1 root root 16 Jul 19 09:16 /usr/local/bin/python-config -python2.5-config

[root@M1 ~]# ls -l /usr/bin/python*
-rwxr-xr-x 2 root root 5396 May 2 16:28 /usr/bin/python
lrwxrwxrwx 1 root root 6 Jul 18 12:20 /usr/bin/python2 -python
-rwxr-xr-x 2 root root 5396 May 2 16:28 /usr/bin/python2.3

[root@M1 ~]# which python
/usr/local/bin/python

[root@M1 ~]# /usr/local/bin/python -c "import sys; print sys.executable; print sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Jul 19 2007, 09:13:48)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-8)]

[root@M1 ~]# env python -c "import sys; print sys.executable; print sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Jul 19 2007, 09:13:48)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-8)]

[root@M1 ~]# python -c "import sys; print sys.executable; print sys.version; set()"
/usr/local/bin/python
2.3.4 (#1, May 2 2007, 19:26:00)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-8)]
Traceback (most recent call last):
File "<string>", line 1, in ?
NameError: name 'set' is not defined
---------------------------------------------------------------------------------
On a different machine, with same setup (as far as I can tell), I get the expected
results:
---------------------------------------------------------------------------------
[root@M2 ~]# /usr/local/bin/python -c "import sys; print sys.executable; print sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Feb 8 2007, 16:29:18)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)]

[root@M2 ~]# env python -c "import sys; print sys.executable; print sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Feb 8 2007, 16:29:18)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)]

[root@M2 ~]# python -c "import sys; print sys.executable; print sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Feb 8 2007, 16:29:18)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)]
---------------------------------------------------------------------------------

Can anyone tell me what might be causing the erroneous behavior in the first example?

Thanks,
Jeffrey
Jul 19 '07 #1
3 3889
"Jeffrey Froman" <je*****@fro.manwrote in message
news:13*************@corp.supernews.com...
Hello All,

I have two python versions installed, one in /usr/bin, and one in
/usr/local/bin. However, when invoking python without a full path,
I get the wrong executable with the right sys.executable string!
----------------------------------------------------------------------------
[root@M1 ~]# ls -l /usr/local/bin/python*
-rwxr-xr-x 2 root root 3783810 Jul 19 09:15 /usr/local/bin/python
-rwxr-xr-x 2 root root 3783810 Jul 19 09:15 /usr/local/bin/python2.5
-rwxr-xr-x 1 root root 1281 Jul 19 09:16
/usr/local/bin/python2.5-config
lrwxrwxrwx 1 root root 16 Jul 19 09:16
/usr/local/bin/python-config -python2.5-config

[root@M1 ~]# ls -l /usr/bin/python*
-rwxr-xr-x 2 root root 5396 May 2 16:28 /usr/bin/python
lrwxrwxrwx 1 root root 6 Jul 18 12:20 /usr/bin/python2 -python
-rwxr-xr-x 2 root root 5396 May 2 16:28 /usr/bin/python2.3

[root@M1 ~]# which python
/usr/local/bin/python

[root@M1 ~]# /usr/local/bin/python -c "import sys; print sys.executable;
print sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Jul 19 2007, 09:13:48)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-8)]

[root@M1 ~]# env python -c "import sys; print sys.executable; print
sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Jul 19 2007, 09:13:48)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-8)]

[root@M1 ~]# python -c "import sys; print sys.executable; print
sys.version; set()"
/usr/local/bin/python
2.3.4 (#1, May 2 2007, 19:26:00)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-8)]
Traceback (most recent call last):
File "<string>", line 1, in ?
NameError: name 'set' is not defined
---------------------------------------------------------------------------------
On a different machine, with same setup (as far as I can tell), I get the
expected
results:
---------------------------------------------------------------------------------
[root@M2 ~]# /usr/local/bin/python -c "import sys; print sys.executable;
print sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Feb 8 2007, 16:29:18)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)]

[root@M2 ~]# env python -c "import sys; print sys.executable; print
sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Feb 8 2007, 16:29:18)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)]

[root@M2 ~]# python -c "import sys; print sys.executable; print
sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Feb 8 2007, 16:29:18)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)]
---------------------------------------------------------------------------------

Can anyone tell me what might be causing the erroneous behavior in the
first example?
I think it's because your python directory is in the path before your
python2.5 directory.
Jul 20 '07 #2
"Jeffrey Froman" <je*****@fro.manwrote in message
news:13*************@corp.supernews.com...
Hello All,

I have two python versions installed, one in /usr/bin, and one in
/usr/local/bin. However, when invoking python without a full path,
I get the wrong executable with the right sys.executable string!
----------------------------------------------------------------------------
[root@M1 ~]# ls -l /usr/local/bin/python*
-rwxr-xr-x 2 root root 3783810 Jul 19 09:15 /usr/local/bin/python
-rwxr-xr-x 2 root root 3783810 Jul 19 09:15 /usr/local/bin/python2.5
-rwxr-xr-x 1 root root 1281 Jul 19 09:16
/usr/local/bin/python2.5-config
lrwxrwxrwx 1 root root 16 Jul 19 09:16
/usr/local/bin/python-config -python2.5-config

[root@M1 ~]# ls -l /usr/bin/python*
-rwxr-xr-x 2 root root 5396 May 2 16:28 /usr/bin/python
lrwxrwxrwx 1 root root 6 Jul 18 12:20 /usr/bin/python2 -python
-rwxr-xr-x 2 root root 5396 May 2 16:28 /usr/bin/python2.3

[root@M1 ~]# which python
/usr/local/bin/python

[root@M1 ~]# /usr/local/bin/python -c "import sys; print sys.executable;
print sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Jul 19 2007, 09:13:48)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-8)]

[root@M1 ~]# env python -c "import sys; print sys.executable; print
sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Jul 19 2007, 09:13:48)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-8)]

[root@M1 ~]# python -c "import sys; print sys.executable; print
sys.version; set()"
/usr/local/bin/python
2.3.4 (#1, May 2 2007, 19:26:00)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-8)]
Traceback (most recent call last):
File "<string>", line 1, in ?
NameError: name 'set' is not defined
---------------------------------------------------------------------------------
On a different machine, with same setup (as far as I can tell), I get the
expected
results:
---------------------------------------------------------------------------------
[root@M2 ~]# /usr/local/bin/python -c "import sys; print sys.executable;
print sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Feb 8 2007, 16:29:18)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)]

[root@M2 ~]# env python -c "import sys; print sys.executable; print
sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Feb 8 2007, 16:29:18)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)]

[root@M2 ~]# python -c "import sys; print sys.executable; print
sys.version; set()"
/usr/local/bin/python
2.5 (r25:51908, Feb 8 2007, 16:29:18)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)]
---------------------------------------------------------------------------------

Can anyone tell me what might be causing the erroneous behavior in the
first example?
er, of course I meant python2.3 before python2.5
Jul 20 '07 #3
Jim Langston wrote:
I think it's because your python directory is in the path before your
python2.5 directory.
Thanks for the tip. In fact, /usr/local/bin/python (2.5) is on my PATH
before /usr/bin/python (2.3).

I did find the problem however -- it turns out that caching the executable
path is a feature of the bash shell, possibly a buggy one. After installing
the new executable in /usr/local/bin, bash claimed to be running that
executable, but was actually invoking the cached "python"
at /usr/bin/python.

What sorted out the confusion for me was when someone demonstrated to me how
sys.executable could be fooled:

$ exec -a /usr/bin/foobar python
Python 2.5.1 (r251:54863, May 4 2007, 16:52:23)
[GCC 4.1.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>import sys
sys.executable
'/usr/bin/foobar'

To remove the cached version, I ran:
$ hash -d python

After which, running "python" invoked a properly named /usr/local/bin/python
as expected.
Thanks,
Jeffrey
Jul 22 '07 #4

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

Similar topics

0
by: Fuzzyman | last post by:
Movable Python has just been released on sourceforge. Movable Python is a frozen distribution of Python. It will run python scripts without needing to be installed. ...
118
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely...
5
by: Avi Kak | last post by:
Folks, Does regular expression processing in Python allow for executable code to be embedded inside a regular expression? For example, in Perl the following two statements $regex =...
34
by: Ben Sizer | last post by:
I've installed several different versions of Python across several different versions of MS Windows, and not a single time was the Python directory or the Scripts subdirectory added to the PATH...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...

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.