Author ncoghlan
Recipients geoffreyspear, ncoghlan, ned.deily, nedbat
Date 2018-04-01.05:25:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
It turns out pydoc's CLI is looking specifically for '' in sys.path, but *not* looking for "os.getcwd()".

The resulting sys.path manipulation then goes completely wrong for "python -m pydoc", since it ends up removing "scriptdir" from sys.path, and that's the directory containing "pydoc" and the rest of the standard library.

It surprised me that you were getting the misbehaviour for the direct pydoc command though, as for me, that's a separate script living in `*/bin`, so the misbehaviour doesn't happen (only the bin directory gets removed from sys.path, which is the desired behaviour).

It turns out that behaviour is due to a difference between venv and virtualenv, where the latter defines a shell alias to hide the filesystem level pydoc scripts installed system wide:

$ which pydoc                                                                                                                                       
pydoc ()                                                                                                                                                                                                
    python -m pydoc "$@"                                                                                                                                                                                

and hence will encounter the problem.

So I think there are two changes needed here:

1. Update pydoc.cli() to search sys.path for "os.getcwd()" in addition to searching for the empty string.
2. Rewording the note in the porting guide to explicitly call out checks for "'' in sys.path" in start-up code as potentially requiring updates
Date User Action Args
2018-04-01 05:25:14ncoghlansetrecipients: + ncoghlan, nedbat, ned.deily, geoffreyspear
2018-04-01 05:25:14ncoghlansetmessageid: <>
2018-04-01 05:25:14ncoghlanlinkissue33185 messages
2018-04-01 05:25:14ncoghlancreate