Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about invalid PYTHONUSERBASE #84384

Open
Volker-Weissmann mannequin opened this issue Apr 6, 2020 · 4 comments
Open

Warn about invalid PYTHONUSERBASE #84384

Volker-Weissmann mannequin opened this issue Apr 6, 2020 · 4 comments
Labels
3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@Volker-Weissmann
Copy link
Mannequin

Volker-Weissmann mannequin commented Apr 6, 2020

BPO 40203
Nosy @terryjreedy, @Volker-Weissmann

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 = None
closed_at = None
created_at = <Date 2020-04-06.12:59:15.393>
labels = ['interpreter-core', 'type-feature', '3.9']
title = 'Warn about invalid PYTHONUSERBASE'
updated_at = <Date 2020-04-11.11:54:27.408>
user = 'https://github.com/Volker-Weissmann'

bugs.python.org fields:

activity = <Date 2020-04-11.11:54:27.408>
actor = 'Volker Wei\xc3\x9fmann'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2020-04-06.12:59:15.393>
creator = 'Volker Wei\xc3\x9fmann'
dependencies = []
files = []
hgrepos = []
issue_num = 40203
keywords = []
message_count = 4.0
messages = ['365851', '365857', '366156', '366203']
nosy_count = 2.0
nosy_names = ['terry.reedy', 'Volker Wei\xc3\x9fmann']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue40203'
versions = ['Python 3.9']

@Volker-Weissmann
Copy link
Mannequin Author

Volker-Weissmann mannequin commented Apr 6, 2020

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.

@Volker-Weissmann Volker-Weissmann mannequin added type-feature A feature request or enhancement labels Apr 6, 2020
@Volker-Weissmann
Copy link
Mannequin Author

Volker-Weissmann mannequin commented Apr 6, 2020

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.

@terryjreedy
Copy link
Member

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.

@terryjreedy terryjreedy added interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.9 only security fixes labels Apr 10, 2020
@Volker-Weissmann
Copy link
Mannequin Author

Volker-Weissmann mannequin commented Apr 11, 2020

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

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant