classification
Title: Warn about invalid PYTHONUSERBASE
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Volker Weißmann, terry.reedy
Priority: normal Keywords:

Created on 2020-04-06 12:59 by Volker Weißmann, last changed 2020-04-11 11:54 by Volker Weißmann.

Messages (4)
msg365851 - (view) Author: Volker Weißmann (Volker Weißmann) * Date: 2020-04-06 12:59
https://docs.python.org/2/using/cmdline.html says that PYTHONUSERBASE defines the user base directory. If I understand this correctly, this implies that PYTHONUSERBASE should be a path a directory. I therefore think that python should print a warning if PYTHONUSERBASE is:
1. Not a valid path (e.g. "invalid//path")
2. A path to something else than a directory
3. A non existing path (maybe)


I think that

export PYTHONUSERBASE="invalid//path"
python

should generate a warning, because there is no good reason to do so.
msg365857 - (view) Author: Volker Weißmann (Volker Weißmann) * Date: 2020-04-06 13:56
Forget the thing I said about "invalid//path", but my argument still stands for non existing paths or paths to something else than a directory.
msg366156 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-04-10 21:17
I marked this for 'interpreter Core' because it affects imports and nothing else seemed better.

I marked this for 3.9 because it is too late to change 2.7.  But I don't know whether PYTHONUSERBASE is still treated (or not treated) the same.

Volker, I assume that you meant 'no good reason to not do so'.  A possible reason is that checking the validity of all environmental variables at startup would slow down startup, whereas we have been trying to speed it up.  Also, if PYTHONUSERBASE, in particular, is ever used for an import, a bad value will result in an import error.
msg366203 - (view) Author: Volker Weißmann (Volker Weißmann) * Date: 2020-04-11 11:54
"there is no good reason to do so" meant that there is no good reason to set PYTHONUSERBASE to non existing path or a path that is not a directory.

The history behind this bug report is that I used a program that, because of a bug in this program, set PYTHONUSERBASE to a non existing path, and I wondered why "import cython" raised a ModuleNotFoundError even though I had installed cython.
History
Date User Action Args
2020-04-11 11:54:27Volker Weißmannsetmessages: + msg366203
2020-04-10 21:17:41terry.reedysetversions: + Python 3.9
nosy: + terry.reedy

messages: + msg366156

components: + Interpreter Core
2020-04-06 13:56:56Volker Weißmannsetmessages: + msg365857
2020-04-06 12:59:15Volker Weißmanncreate