FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

pyvenv pydoc.py script causing AttributeErrors on Windows · Issue #62424 · python/cpython · GitHub

Repository navigation

pyvenv pydoc.py script causing AttributeErrors on Windows #62424

Closed

Description

BPO 18224
Nosy @vsajip, @merwok
Files
  • shadow.py: shadow.py test script
  • 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 = 'https://github.com/vsajip'
    closed_at = <Date 2013-06-30.21:12:10.024>
    created_at = <Date 2013-06-15.14:27:13.984>
    labels = ['type-bug', 'OS-windows']
    title = 'pyvenv pydoc.py script causing AttributeErrors on Windows'
    updated_at = <Date 2013-07-02.16:14:06.739>
    user = 'https://bugs.python.org/peterpsantoronet'

    bugs.python.org fields:

    activity = <Date 2013-07-02.16:14:06.739>
    actor = 'eric.araujo'
    assignee = 'vinay.sajip'
    closed = True
    closed_date = <Date 2013-06-30.21:12:10.024>
    closer = 'python-dev'
    components = ['Windows']
    creation = <Date 2013-06-15.14:27:13.984>
    creator = 'peter@psantoro.net'
    dependencies = []
    files = ['30620']
    hgrepos = []
    issue_num = 18224
    keywords = []
    message_count = 8.0
    messages = ['191210', '191292', '191345', '191348', '191349', '191987', '192085', '192208']
    nosy_count = 4.0
    nosy_names = ['vinay.sajip', 'eric.araujo', 'python-dev', 'peter@psantoro.net']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue18224'
    versions = ['Python 3.3', 'Python 3.4']

    Activity

    1. peterpsantoronet commented on Jun 15, 2013

      peterpsantoronetmannequin
      MannequinAuthor

      I've recently hit an issue with pyvenv in Python 3.3.2 that is causing AttributeErrors in other packages on Windows (see https://groups.google.com/forum/?fromgroups#!topic/pylons-discuss/FpOSMDpdvy4). Here's what I believe is going on:

      On Windows, the pyvenv pydoc script has a .py extension - so import finds it instead of the system's pydoc module. On Linux, the pyvenv pydoc script doesn't have an extension - so import finds the system's pydoc module.

      I believe the Windows pyvenv pydoc.py script should be renamed to something like pydocs.py to prevent AttributeErrors.

    2. vsajip commented on Jun 16, 2013

      Member

      The pyvenv pydoc script should be in the venv's Scripts folder, which is not (normally) on sys.path - the venv's Lib\site-packages is. Can you provide a small script which demonstrates the problem while confirming that the venv's Scripts folder has not been added to sys.path?

    3. peterpsantoronet commented on Jun 17, 2013

      peterpsantoronetmannequin
      MannequinAuthor

      As requested, I've attached a small test script called shadow.py. Steps to reproduce:

      1. pyvenv.py bugtest
      2. copy the attached shadow.py script to bugtest and bugtest\scripts
      3. cd bugtest
      4. run shadow.py (first entry in sys.path is refers to bugtest directory per Python docs; finds the systems's pydoc module)
      5. run bugtest\shadow.py (first entry in sys.path refers to bugtest\scripts directory per Python docs; finds the bugtest\scripts pydoc module instead of the system's pydoc module)

      According to the Python documentation (http://docs.python.org/3/library/sys.html#sys.path):

      "As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter. If the script directory is not available (e.g. if the interpreter is invoked interactively or if the script is read from standard input), path[0] is the empty string, which directs Python to search modules in the current directory first. Notice that the script directory is inserted before the entries inserted as a result of PYTHONPATH."

      Maybe I'm missing something here, but isn't this problem caused by the fact that Python initializes sys.path[0] to contain the directory of the executing script and that having pydoc.py in that same directory (i.e. the venv's scripts directory) shadows the system's pydoc.py module? On Linux, I didn't have this problem, because the pydoc script doesn't have the .py extension. However, if you rename the pydoc script on Linux to pydoc.py, the same problem occurs.

      I don't think a pydoc.py (or any other .py file which shadows a system module) can exist in the venv scripts (or bin) directory without shadowing/breaking the system provided module. Maybe a pydoc.exe or pydoc.bat file is needed on Windows? Another option would be to rename the pydoc.py file to something like pydocs.py, but that would be incompatible with other platforms and the existing documentation.

    4. vsajip commented on Jun 17, 2013

      Member

      the fact that Python initializes sys.path[0] to contain the directory of the executing script

      Of course, silly me. Sorry.

      I would prefer to remove the pydoc script altogether. The other alternative would be to rename it to pydoc-script.py and have a pydoc.exe adjacent to it (this is how scripts installed with setuptools or distlib work). However, the simple launcher which would be pydoc.exe is not currently part of Python. I think the best thing would be for me to post on python-dev to see what views people there have about these alternatives.

    5. vsajip commented on Jun 17, 2013

      Member

      Rethinking, renaming seems more reasonable. I've posted about it to python-dev:

      http://mail.python.org/pipermail/python-dev/2013-June/126904.html

    6. vsajip commented on Jun 28, 2013

      Member

      On further reflection: the pydoc script adds no value over and above "python -m pydoc <args>", so I think I will remove it.

    7. self-assigned this
      on Jun 28, 2013
    8. python-dev commented on Jun 30, 2013

      python-devmannequin
      Mannequin

      New changeset af837bf390d0 by Vinay Sajip in branch '3.3':
      Issue bpo-18224: Removed pydoc script from created venv, as it causes problems on Windows and adds no value over and above python -m pydoc ...
      http://hg.python.org/cpython/rev/af837bf390d0

      New changeset de73e7ffabb3 by Vinay Sajip in branch 'default':
      Closes bpo-18224: Removed pydoc script from created venv, as it causes problems on Windows and adds no value over and above python -m pydoc ...
      http://hg.python.org/cpython/rev/de73e7ffabb3

      New changeset c17fa2cbad43 by Vinay Sajip in branch '3.3':
      Issue bpo-18224: Updated test.
      http://hg.python.org/cpython/rev/c17fa2cbad43

      New changeset ae69436eb7c2 by Vinay Sajip in branch 'default':
      Issue bpo-18224: Updated test.
      http://hg.python.org/cpython/rev/ae69436eb7c2

    9. merwok commented on Jul 2, 2013

      Member

      That’s too bad; it’s annoying to lose the ability to just use “pydoc x” if a venv is activated.

    10. 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

    Labels

    OS-windowstype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL