473,769 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3948
"Jeffrey Froman" <je*****@fro.ma nwrote in message
news:13******** *****@corp.supe rnews.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.ma nwrote in message
news:13******** *****@corp.supe rnews.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.executabl e
'/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
1919
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. http://sourceforge.net/projects/movpy http://www.voidspace.org.uk/python/movpy Fancy trying out Python 2.4 without installing it ? Want a distribution of python you can carry around on a flash card ? Need to test scripts with several versions of python ? Movable Python may...
118
6740
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 hated it, having learned C++ a few years prior. They didn't teach Lisp at all and instead expected us to learn on our own. I wasn't aware I had to uproot my thought process to "get" it and wound up feeling like a moron. In learning Python I've...
5
2321
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 = qr/hello(?{print "saw hello\n"})mello(?{print "saw mello\n"})/; "jellohellomello" =~ /$regex/;
34
3965
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 environment variable. Every time, I've had to go through and add this by hand, to have something resembling a usable Python installation. No such problems on Linux, whether it be Mandrake/Mandriva, Fedora Core, or Kubuntu. So why is the Windows...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9995
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5304
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.