question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
rchiodocommented, 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.

1reaction
Mistobaancommented, Aug 24, 2019

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
Read more comments on GitHub >

github_iconTop Results From Across the Web

Conda environments not showing up in Jupyter Notebook
The problem is that Jupyter Notebook does not recognize the new environment I just created. No matter I start Jupyter Notebook from the...
Read more >
Installed modules cannot be imported (ModuleNotFound error)
Looking at the path, I realized it is different from the path for jupyter. Thus, I installed it in the same directory using...
Read more >
Jupyter / IPython: After editing a module, changes are not ...
There are several ways to work around this issue. 1) The simplest and most certain is to restart the ipython kernel after changing...
Read more >
Configuring user environments - JupyterHub - Read the Docs
To deploy JupyterHub means you are providing Jupyter notebook environments for multiple users. Often, this includes a desire to configure the user environment...
Read more >
Import: Modules and Packages - Python Like You Mean It
A module can be imported into an interactive console environment (e.g. a Jupyter notebook) or into another module. Importing a module executes that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found