VS Code version: 1.37.1
Extension version (available under the Extensions sidebar): 2019.8.30787
OS and version: windows 10
Python version (& distribution if applicable, e.g. Anaconda): python 3.7.1
Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
Relevant/affected Python packages and their versions: -
Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info microsoft/vscode-python#3977): -
with .env file that points to some subdir that is the package, both regular run and interactive run of some script should recognize the modules.
ipython can't recognize non workspace PYTHONPATH/ sys.path.append("..")
+.env (in which the python path of src is appended: PYTHONPATH=./src;${PYTHONPATH})
+src
+-foo
+--__init__.py
+--foo.py
+-bar
+--bar.py
in bar.py call "import foo.foo as foo" when running interactively.
one can also try to sys.path.append("..") but this also doesnt work in this case...
This action works in Binder and in pycharm (using "mark as package dir" + "mark as source dir" of src).
probably the most convenient solution is to implement "mark as package dir" + "mark as source dir" like pycharm which will work for regular and ipython runs.
a more un-IDE solution is just to enable .env to work with ipython.
@YoniChechik. Thanks for the report on this. You're correct that interactive isn't picking this up. We'll look at fixing this up, either via marking or respecting the .env setting.
I also noticed that the interactive is launched always inside the directory of the first project of a workspace.
Is there a mini document on how to hack iPython's extension?
this probably relates to this microsoft/vscode-jupyter#3141.
rethinking about this, probably the best is doing both env var and choosing to run via file-dir is by a proper launch configuration for ipython.
This is kind of related to:
https://github.com/microsoft/vscode-python/issues/6850
Having the same issue. Does the P0 label mean a fix will be part of the next release?
Also, I was wondering if this was a design decision or due to some limitations? (Copied from here.)
When PYTHONPATH is set using an .env file, it will affect anything the extension does on your behalf and actions performed by the debugger, but it will not affect tools run in the terminal.
Wouldn't it be best to have .env be the single source of truth for all parts of VS Code including the integrated terminal?
This bug is currently in the 'Nice to have bug fixes for feb 2020', so it's a maybe for fixing now. More likely for the March release.
Wouldn't it be best to have .env be the single source of truth for all parts of VS Code including the integrated terminal?
I may be wrong, but I believe the .env file is supported by the python extension, but not be VS code itself. VS code is responsible for the integrated terminal, so the integrated terminal doesn't support .env files.
This isn't working for me.
I added the following to my .env:
PYTHONPATH=../libraries/my_library;${PYTHONPATH}
But this has no effect on the sys.path.
Caused by microsoft/vscode-jupyter#2254. Fixing that will fix this.
Most helpful comment
This bug is currently in the 'Nice to have bug fixes for feb 2020', so it's a maybe for fixing now. More likely for the March release.
I may be wrong, but I believe the .env file is supported by the python extension, but not be VS code itself. VS code is responsible for the integrated terminal, so the integrated terminal doesn't support .env files.