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.

can not load system-site-packages when using a venv ipykernel

See original GitHub issue

Environment data

  • VS Code version: 1.67.1
  • Jupyter Extension version (available under the Extensions sidebar): v2022.4.1011282140
  • Python Extension version (available under the Extensions sidebar): v2022.6.1
  • OS (Windows | Mac | Linux distro) and version: Windows 19044.1645
  • Python and/or Anaconda version: 3.8.10
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
  • Jupyter server running: Local

Expected behaviour

fail to import a module installed in %userprofile% in *.ipynb files but it works in *.py files.

I have set ‘include-system-site-packages = true’ in pyvenv.cfg.

Actual behaviour

failed with ModuleNotFoundError

Steps to reproduce:

  1. create a virtual enviroment. then install ipykernel.
  2. import a module installed in %userprofile% in *.ipynb files.
  3. run a cell.

图片

Logs

Output for Jupyter in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Jupyter)

XXX

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
DonJayamannecommented, May 11, 2022

his was because conda environments were picking up the wrong stuff?

Sorry for not explaining that, yes thats correct. We found that it completely messes up things. And decided not to add it. This is the first time we’ve had a user complain about this, seems legitimate though. I guess we could add this back if its a non-conda and virtual environment. Then again there are a number of different virtual environments, are poetry considered virtual? We need to be careful in adding them, else we could end up adding them even for environments that would never get them regardless.

I’d suggest just adding this back only for virtual environments (venv, virtualenv, virtualenvwrapper, etc). We used to have startup code that did this, which was later removed.

1reaction
rchiodocommented, May 11, 2022

Thanks for the bug.

Can you print out the sys.path in a notebook and the sys.path in a python terminal and show the difference here?

We should be picking up the pyvenv.cfg settings so I’d like to see what the difference is.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running Jupyter notebook in a virtualenv: installed sklearn ...
To install jupyter, (and in a first instance pip, that does not get installed neither in your virtual environment with this command) but ......
Read more >
Creating Python Virtual Environment and how to add it to ...
We will not install virtualenv on Linux because we will use venv function to create virtual environment. Install ipykernel.
Read more >
Use Virtual Environments Inside Jupyter Notebooks & Jupter ...
We'll do this by creating an isolated python virtual environment for each notebook, so that each notebooks runs inside it's own environment. If...
Read more >
venv — Creation of virtual environments — Python 3.11.1 ...
Creating virtual environments¶ ... Running this command creates the target directory (creating any parent directories that don't exist already) and places a ...
Read more >
Python Virtual Environments - Office of Research Computing
A Python Virtual environment built on Argo (for example) will not work on Hopper. On Argo, we recommend that you use virtualenv as...
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