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

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

Closed
ruiy326 opened this issue May 11, 2022 · 10 comments
Closed

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

ruiy326 opened this issue May 11, 2022 · 10 comments
Assignees

Comments

@ruiy326
Copy link

ruiy326 commented May 11, 2022

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

@ruiy326 ruiy326 added the bug Issue identified by VS Code Team member as probable bug label May 11, 2022
@github-actions github-actions bot added the triage-needed Issue needs to be triaged label May 11, 2022
@rchiodo
Copy link
Contributor

rchiodo commented 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.

@rchiodo rchiodo added the info-needed Issue requires more information from poster label May 11, 2022
@DonJayamanne
Copy link
Contributor

@rchiodo we don't load system wide global packages in non global python paths. this is by design.

@rchiodo
Copy link
Contributor

rchiodo commented May 11, 2022

@DonJayamanne are you saying we remove them? I just thought we didn't add them to the list. But we don't change them, do we?

@DonJayamanne
Copy link
Contributor

We do remove them.

I just thought we didn't add them to the list

Thats correct, this is made possible by removing them from the list.

@rchiodo
Copy link
Contributor

rchiodo commented May 11, 2022

Why do we remove them? This was because conda environments were picking up the wrong stuff?

@DonJayamanne
Copy link
Contributor

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.

@ruiy326
Copy link
Author

ruiy326 commented May 12, 2022

@DonJayamanne @rchiodo Thanks for your replies. When using VScode 1.66.2 with jupyter 2022.2, I had noticed that a venv ipykernel can not be started if any dependent packages are inherited from the global python path. But then a global package can still be used in a virtual enviroment.
I didn't expect sharing global packages to be removed. So I submitted this bug.

@greazer greazer added notebook-regression and removed info-needed Issue requires more information from poster triage-needed Issue needs to be triaged labels May 12, 2022
@greazer greazer added this to the June 2022 milestone May 12, 2022
@greazer
Copy link
Member

greazer commented May 12, 2022

We think we can honor adding this request by reading the pyvenv.cfg file and if the system site packages is set to true, we append site package path.

@ruiy326 ruiy326 closed this as completed May 13, 2022
@rchiodo
Copy link
Contributor

rchiodo commented May 13, 2022

@ruiy326 did you mean to close this? We plan on fixing this soon.

@rchiodo rchiodo reopened this May 13, 2022
@github-actions github-actions bot added the triage-needed Issue needs to be triaged label May 13, 2022
@greazer greazer removed triage-needed Issue needs to be triaged iteration-candidate labels May 16, 2022
@greazer
Copy link
Member

greazer commented May 16, 2022

Resolving as dupe of #9995

@greazer greazer closed this as completed May 16, 2022
@greazer greazer modified the milestones: June 2022, May 2022 May 16, 2022
@roblourens roblourens removed this from the May 2022 milestone Jun 3, 2022
@roblourens roblourens removed the bug Issue identified by VS Code Team member as probable bug label Jun 3, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 4, 2023
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

5 participants