Skip to content

Document absoluteness of sys.executable #57611

Closed

Description

@merwok
BPO 13402
Nosy @ronaldoussoren, @pitrou, @vstinner, @pjenvey, @ned-deily, @merwok, @DinoV, @florentx, @ericsnowcurrently, @akheron, @eryksun, @bradlarsen
Files
  • issue13402.patch
  • issue13402_v2.patch
  • issue13402_v3.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-02-02.19:30:22.171>
    created_at = <Date 2011-11-14.16:50:37.246>
    labels = ['docs']
    title = 'Document absoluteness of sys.executable'
    updated_at = <Date 2016-07-12.03:05:43.826>
    user = 'https://github.com/merwok'

    bugs.python.org fields:

    activity = <Date 2016-07-12.03:05:43.826>
    actor = 'ned.deily'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2012-02-02.19:30:22.171>
    closer = 'python-dev'
    components = ['Documentation']
    creation = <Date 2011-11-14.16:50:37.246>
    creator = 'eric.araujo'
    dependencies = []
    files = ['23738', '23958', '24380']
    hgrepos = []
    issue_num = 13402
    keywords = ['patch']
    message_count = 20.0
    messages = ['147609', '148006', '148029', '148042', '148043', '148317', '148355', '148356', '148357', '149468', '149483', '149511', '150460', '152403', '152473', '270210', '270217', '270222', '270223', '270224']
    nosy_count = 16.0
    nosy_names = ['ronaldoussoren', 'pitrou', 'vstinner', 'pjenvey', 'schmir', 'ned.deily', 'eric.araujo', 'dino.viehland', 'eli.bendersky', 'flox', 'docs@python', 'python-dev', 'eric.snow', 'petri.lehtinen', 'eryksun', 'blarsen']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue13402'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    Activity

    1. merwok commented on Nov 14, 2011

      @merwok
      MemberAuthor

      I wanted to know if sys.executable was always an absolute path but the doc does not talk about that.

      (My use case is that I’d like to reload a process and I wonder if I can call os.execve or if I need to use os.execvpe.)

    2. akheron commented on Nov 20, 2011

      @akheron
      Member

      Attached a patch.

    3. elibendersky commented on Nov 21, 2011

      elibenderskymannequin
      Mannequin

      LGTM

    4. merwok commented on Nov 21, 2011

      @merwok
      MemberAuthor

      Patch looks good, but are you 100% sure that sys.executable is always absolute? (On all OSes, under multiprocessing, etc?)

    5. akheron commented on Nov 21, 2011

      @akheron
      Member

      Éric Araujo wrote:

      Patch looks good, but are you 100% sure that sys.executable is
      always absolute? (On all OSes, under multiprocessing, etc?)

      Well, its value is computed by a function named
      Py_GetProgramFullPath(), so I'm quite sure. I had a quick look on what
      the function is doing, but it was quite complicated. I can check it
      better if needed.

    6. merwok commented on Nov 25, 2011

      @merwok
      MemberAuthor

      This is the bug I was thinking about: bpo-7774. Adding some people from that discussion to nosy.

    7. pitrou commented on Nov 25, 2011

      @pitrou
      Member

      LGTM too.
      You could also add a test to test_sys ensuring that sys.executable is always executable.

    8. vstinner commented on Nov 25, 2011

      @vstinner
      Member

      You could also add a test to test_sys ensuring that sys.executable
      is always executable.

      And that sys.executable is absolute?

      sys.executable is an empty string if sys.argv[0] has been changed and Python is unable to retrieve the real path to the Python executable. See the issue bpo-7774. The fact that sys.executable can be empty should be documented.

    9. pitrou commented on Nov 25, 2011

      @pitrou
      Member

      > You could also add a test to test_sys ensuring that sys.executable
      > is always executable.

      And that sys.executable is absolute?

      Er, yes, that's what I meant. Sorry.

    10. akheron commented on Dec 14, 2011

      @akheron
      Member

      Attaching an updated patch. The documentation now says that sys.executable may be an empty string. The patch also adds a test to make sure that sys.executable is absolute.

    11. pjenvey commented on Dec 14, 2011

      @pjenvey
      Member

      sys.executable can be None on Jython (and I believe IronPython) when ran in an 'embedded' mode

    12. akheron commented on Dec 15, 2011

      @akheron
      Member

      sys.executable can be None on Jython (and I believe IronPython) when ran in an 'embedded' mode

      In CPython, embedding doesn't change the behavior.

    13. merwok commented on Jan 2, 2012

      @merwok
      MemberAuthor

      This discussion seems relevant: http://mail.python.org/pipermail/python-dev/2006-March/062453.html (it talks about the meaning of sys.executable, special cases such as embedded Python and functions that implement it (so we can have a look at that code)).

    14. akheron commented on Jan 31, 2012

      @akheron
      Member

      Attached one more patch. The documentation now also mentions None as a possible value.

    15. python-dev commented on Feb 2, 2012

      python-devmannequin
      Mannequin

      New changeset fdcda5b74317 by Petri Lehtinen in branch '3.2':
      Document absoluteness of sys.executable
      http://hg.python.org/cpython/rev/fdcda5b74317

      New changeset 8b591a86fc91 by Petri Lehtinen in branch 'default':
      Merge branch 3.2
      http://hg.python.org/cpython/rev/8b591a86fc91

      New changeset c351536e804a by Petri Lehtinen in branch '2.7':
      Document absoluteness of sys.executable
      http://hg.python.org/cpython/rev/c351536e804a

    16. bradlarsen commented on Jul 11, 2016

      bradlarsenmannequin
      Mannequin

      It looks like sys.executable is *not* always an absolute path. In Python 2.7:

          $ which python2.7
          /opt/local/bin/python2.7
          $ cd /opt/local/bin
          $ ../bin/python2.7 -m 'import sys; print(sys.executable)'
          /opt/local/bin/../bin/python2.7

      Also in Python 3.5:

          $ which python3.5
          /opt/local/bin/python3.5
          $ cd /opt/local/bin
          $ ../bin/python3.5 -m 'import sys; print(sys.executable)'
          /opt/local/bin/../bin/python3.5
    17. eryksun commented on Jul 12, 2016

      @eryksun
      Contributor

      "/opt/local/bin/../bin/python2.7" is an absolute path.

          >>> os.path.isabs('/opt/local/bin/../bin/python2.7')
          True

      It's not relative to the working directory.

    18. ned-deily commented on Jul 12, 2016

      @ned-deily
      Member

      @blarsen, and there's something strange about your example. '-m' won't work with a real python executable, presumably you meant '-c'. And judging from the paths involved, I'm guessing you are using MacPorts on OS X. With either MacPorts or any other OS X framework build, you wouldn't see results like that with -c.

      ../bin/python3.5 -c 'import sys; print(sys.executable)'
      /opt/local/bin/python3.5
      ../bin/python2.7 -c 'import sys; print(sys.executable)'
      /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python

      So I'm guessing what's in ../bin/python3.7 and ../bin/python3.5 is something other than the normal python bootstrap binaries.

    19. bradlarsen commented on Jul 12, 2016

      bradlarsenmannequin
      Mannequin

      @eryksun, you are right! The output is an absolute path as far as os.path.isabs is concerned.

      @ned.deily, you are right about my example --- I transcribed it wrong, and it should be -c.

      The system in question is not a Mac OS system, but a Linux system with newer Python versions than what come with the system installed to /opt/local. These are compiled from source, but without any modifications.

      I'm commenting here because I'm seeing the test_sys test from the regression suite fail in a slightly modified version of Python that ships with a product. In particular, in Lib/test/test_sys.py around line 640, we have this:

      @unittest.skipIf(sys.base_prefix != sys.prefix,
                       'Test is not venv-compatible')
      def test_executable(self):
          # sys.executable should be absolute
          self.assertEqual(os.path.abspath(sys.executable), sys.executable)
      

      Yes, /opt/local/bin/../bin/python3.5 is an absolute path as far as os.path.isabs is concerned, but os.path.abspath('/opt/local/bin/../bin/python3.5') gives '/opt/local/bin/python3.5', and the test fails. So maybe the documentation is fine but the test is wrong?

    20. ned-deily commented on Jul 12, 2016

      @ned-deily
      Member

      @blarsen, OK, but if you want to pursue this, please open a new issue against the current versions. This issue was closed years ago and against earlier versions so your comments will not get acted on.

    21. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      docsDocumentation in the Doc dir

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions