Python version changes, sys.executable does not - Python

This is a discussion on Python version changes, sys.executable does not - Python ; 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 ...

+ Reply to Thread
Results 1 to 4 of 4

Python version changes, sys.executable does not

  1. Default 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

  2. Default Re: Python version changes, sys.executable does not

    "Jeffrey Froman" <jeffrey@fro.man> wrote in message
    news:139v9oe22rihh40@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.



  3. Default Re: Python version changes, sys.executable does not

    "Jeffrey Froman" <jeffrey@fro.man> wrote in message
    news:139v9oe22rihh40@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



  4. Default Re: Python version changes, sys.executable does not

    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

+ Reply to Thread

Similar Threads

  1. Creating Installer or Executable in Python
    By Application Development in forum Python
    Replies: 10
    Last Post: 11-15-2007, 01:30 PM
  2. ruby lib version (1.8.6) doesn't match executable version
    By Application Development in forum RUBY
    Replies: 1
    Last Post: 10-24-2007, 06:13 AM
  3. programmatically get labview project executable version
    By Application Development in forum labview
    Replies: 0
    Last Post: 08-10-2007, 02:10 PM
  4. How to create a single executable of a Python program
    By Application Development in forum Python
    Replies: 11
    Last Post: 07-26-2007, 04:14 AM
  5. Re: Copy TRE-files version 8.2 manually with a executable
    By Application Development in forum labview
    Replies: 0
    Last Post: 07-25-2007, 11:10 AM