vscode-python: Activated environments not resolving PYTHONPATH=./ to a fully qualified value
Assume you have a .env file with the following contents
PYTHONPATH=./
When you debug a Python file, then the env variable is resolved and the PYTHONPATH value is fully resolved to the full path of the workspace. I.e. Workspace path is now in the current Python path (sys.path)
However when Jupyter extension gets the activated env variables the above value is not resolved, as a result the workspace directory is not added to the PATH or PYTHONPATH value in the env variables.
Looks like Python ext only resolves this for debugging of python code and not when returning activated variables.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16 (1 by maintainers)
We only support resolving a few environment variables in paths (ex.
HOME,USERNAME,VIRTUAL_ENV), but yes we do support relative paths there.The
PYTHONPATHenvironment variable is handled differently. We don’t support it in all paths. We just check if it’s set (via thepython._envPYTHONPATHconfig setting) and if so, add it to ourextraPaths. Although we support relative paths inPYTHONPATH(ex../foo), it appears that./gets incorrectly resolved to\\rather than the workspace root. This is also true if you directly set"python.analysis.extraPaths": ["./"]though. I’m not sure we care about that scenario since I don’t think it makes sense to add the workspace root toextraPaths.Adding @heejaechang since, coincidentally, he was also looking at our code that handles the
PYTHONPATHenv var today.debugpy doesn’t know anything about workspaces. However, if you have a launch configuration with
"program":"/foo/bar/baz.py"and no"cwd", it will assume that “cwd” should be “/foo/bar”. Thus having.in PYTHONPATH works in practice in this scenario.If the path is not absolute or you use “module”, it will not do anything special, so all relative paths will be resolved depending on what the current directory is for the terminal running the debuggee.