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
Unexpected effect of sys.pycache_prefix = "" #90135
Comments
Setting sys.pycache_prefix = "", re-creates CWD structure under current directory, e.g. if run from /Users/foo/test, will create /Users/foo/test/Users/foo/test/myfile.pyc . Is that intentional? It seems a little weird. At least it might be good to document it. |
(I forgot to mention this happens on MacOS). |
It works as designed and documented. An empty string is considered a relative directory. https://docs.python.org/3/library/sys.html#sys.pycache_prefix
|
If CWD=/a/b and pycache_prefix=c, the resulting dir is /a/b/c as I would expect. If CWD=/a/b and pycache_prefix='', I would expect resulting dir to be /a/b For example as the shell |
Can this also create the risk of 'path too long' issues? |
The cache prefix mirrors the directory structure. Python takes the absolute path to the .py file, converts the path to a relative path by stripping off the leading slash, and finally joins the path with the prefix. Take this example: $ PYTHONPYCACHEPREFIX=/tmp/pycache python3.10 -c pass This will create the cache file "/tmp/pycache/usr/lib64/python3.10/os.cpython-310.pyc" for the Python file "/usr/lib64/python3.10/os.py. |
Thanks, I've misunderstood how it works. It makes sense now. Closing as not a bug. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: