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.
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?
peterpsantoronet commented on Jun 17, 2013
peterpsantoronetmannequin
MannequinAuthor
More actions
As requested, I've attached a small test script called shadow.py. Steps to reproduce:
pyvenv.py bugtest
copy the attached shadow.py script to bugtest and bugtest\scripts
cd bugtest
run shadow.py (first entry in sys.path is refers to bugtest directory per Python docs; finds the systems's pydoc module)
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)
"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.
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.
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
Activity
peterpsantoronet commented on Jun 15, 2013
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.
vsajip commented on Jun 16, 2013
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?
peterpsantoronet commented on Jun 17, 2013
As requested, I've attached a small test script called shadow.py. Steps to reproduce:
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.
vsajip commented on Jun 17, 2013
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.
vsajip commented on Jun 17, 2013
Rethinking, renaming seems more reasonable. I've posted about it to python-dev:
http://mail.python.org/pipermail/python-dev/2013-June/126904.html
vsajip commented on Jun 28, 2013
On further reflection: the pydoc script adds no value over and above "python -m pydoc <args>", so I think I will remove it.
python-dev commented on Jun 30, 2013
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
merwok commented on Jul 2, 2013
That’s too bad; it’s annoying to lose the ability to just use “pydoc x” if a venv is activated.