Moving from bpo-29326 ==== Hi Steve. I'll try to explain what is my motivation. I need a reliable way to run Python (not matter embedded or not) in isolated mode, but still having current directory in `sys.path` (empty entry). Ironically I could misuse normal mode to simulate isolated mode with specified %PYTHONPATH% (which is not much handy, by the way), but hiding Windows Registry keys would look pretty hard (it is impossible to make a bat/cmd wrapper). Possibility to search %PYTHONPATH% in HKLM entries makes it even worse. Empty entry in `sys.path` is a extremely popular thing, and many software depend on it. It looks like a bug that isolated mode cannot support such entry. # How would I fix it. Possibly we should allow another keyword for adding an empty entry (like we have an exclusion for `import site`). Ideas are appreciated.
If your ._pth includes `import site`, then including a blank line in a `anything.pth` file should add the entry. Alternatively, if you can add "import sys; sys.path.insert(0, '')" to the start of your code that depends on it you should be fine.
Unfortunately this is not true: "Blank lines and lines beginning with # are skipped." (https://docs.python.org/3/library/site.html#index-1) I'm not sure we should change this behavior as it would make huge impact on usage of `pth` files by users (`._pth`, on the contrary, is the only one per distribution and managed by the distribution). I could easily add `''` to `sys.path` manually if I had one script or even dozen of them, but as the solution that alternative is not acceptable. :(
You could add the line import sys; sys.path.insert(0, '') to a .pth file. The documentation you pointed out states that lines starting with "import" are executed...
History
Date
User
Action
Args
2022-04-11 14:59:01
admin
set
github: 77879
2020-02-05 02:53:11
steve.dower
set
status: open -> closedresolution: rejectedstage: resolved