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

!pip not installing packages as expected #6864

Closed
rebornix opened this issue Jul 28, 2021 · 7 comments
Closed

!pip not installing packages as expected #6864

rebornix opened this issue Jul 28, 2021 · 7 comments
Assignees
Labels
notebook-kernel Kernels issues (start/restart/switch/execution, install ipykernel)
Milestone

Comments

@rebornix
Copy link
Member

I recently installed Python 3.9.6 from python.org and tried to run notebook against this interpreter but ran into a couple of issues.

Problem

  • Install Python 3.9.6, which was not added to the PATH
  • Open a notebook, Python 3.9.6 is listed in kernel list, select this kernel
  • Run import pandas as pd, it prompts to ask to install ipykernel
  • After ipykernel is installed, rerun the cell, we get error "pandas is missing"
  • Insert a new cell, run !pip install pandas, it works but it installs the pandas package to python 2.7 as that the interpreter in the PATH

image

Proposal

The underling problem is the disconnect between Python active interpreter, Jupyter kernel, and the python interpreter in the PATH. If users are using pyenv, venv, or conda, the extension will activate the environment, which will set up the environment properly, however we don't have such thing for the vanilla Python interpreter.

We should probably

  • Show a warning for !pip if the pip in the PATH is not the one in the interpreter behind the selected kernel
  • Automatically add the pip from the interpreter of the selected kernel to the PATH temporarily
@rebornix rebornix added bug Issue identified by VS Code Team member as probable bug debt Code quality issues labels Jul 28, 2021
@rchiodo
Copy link
Contributor

rchiodo commented Jul 28, 2021

%pip is actually the command you should use. !pip just does a shell execute and will use the python on the path.

https://stackoverflow.com/questions/65547021/difference-between-pip-and-pip-in-python-jupyter-notebook-and-colab

@rchiodo rchiodo removed their assignment Jul 28, 2021
@rchiodo
Copy link
Contributor

rchiodo commented Jul 28, 2021

Personally I think we should put up an error if the user has !pip or !conda as they don't do what the user expects.

@rchiodo rchiodo added enhancement and removed bug Issue identified by VS Code Team member as probable bug debt Code quality issues labels Jul 28, 2021
@rchiodo rchiodo changed the title Installing missing packages in a notebook !pip not installing packages as expected Jul 28, 2021
@DonJayamanne
Copy link
Contributor

DonJayamanne commented Jul 28, 2021

Your is a regression. which pytjon used to point to the right interpreter, I fixed that, I even recall shifting this working at one point to peng.

And yes, we should use %pip

@rebornix
Copy link
Member Author

Agree that we should show an error for !pip and suggest users to use %pip as a code action.

@DonJayamanne
Copy link
Contributor

that we should show an error for !pip and suggest

Not sure about the error, as users might want to do that. A suggestion probably.

@greazer greazer added notebook-kernel Kernels issues (start/restart/switch/execution, install ipykernel) and removed needs-triage labels Jul 29, 2021
@greazer
Copy link
Member

greazer commented Jul 29, 2021

This is a common problem in the jupyter tools ecosystem all up. Consider using code-level diagnostics (squiggles, etc) to notify the user.

@DonJayamanne
Copy link
Contributor

Suggestion:

  • Add a diagnostic error for usage of !pip and recommend using %pip or %conda if its a conda environment.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
notebook-kernel Kernels issues (start/restart/switch/execution, install ipykernel)
Projects
None yet
Development

No branches or pull requests

4 participants