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

ipython kernel doesn't recognize user def modules of .env #3162

Closed
YoniChechik opened this issue Aug 18, 2019 · 9 comments
Closed

ipython kernel doesn't recognize user def modules of .env #3162

YoniChechik opened this issue Aug 18, 2019 · 9 comments

Comments

@YoniChechik
Copy link

Environment data

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): -

Expected behavior

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.

Actual behavior

ipython can't recognize non workspace PYTHONPATH/ sys.path.append("..")

Steps to reproduce:

workdir
+.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.

@IanMatthewHuff
Copy link
Member

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

@Mistobaan
Copy link

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?

  • where is the logic where the main python interpreter is launched
  • where is the logic to draw the interactive iPython window
  • how to customize an iPython cell
  • where is the logic for the shift-enter behavior

@YoniChechik
Copy link
Author

this probably relates to this #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.

@rchiodo
Copy link
Contributor

rchiodo commented Dec 20, 2019

@janosh
Copy link
Contributor

janosh commented Jan 29, 2020

Having the same issue. Does the P0 label mean a fix will be part of the next release?

@janosh
Copy link
Contributor

janosh commented Jan 29, 2020

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?

@rchiodo
Copy link
Contributor

rchiodo commented Jan 29, 2020

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.

@DonJayamanne DonJayamanne self-assigned this Feb 7, 2020
@rchiodo
Copy link
Contributor

rchiodo commented Feb 14, 2020

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.

@greazer
Copy link
Member

greazer commented Feb 24, 2020

Caused by #2254. Fixing that will fix this.

@greazer greazer closed this as completed Feb 24, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Mar 10, 2020
@microsoft microsoft unlocked this conversation Nov 14, 2020
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants