admin管理员组

文章数量:1123051

Despite pip finds the package I can not import it in jupyter notebook - please see the screenshot that I've attached for the clarity. Describes the path to executable and the command prompt. Is something wrong with the kernel?

How can I fix this to use the redlines package in my kernel?

Screenshot from the situation

Despite pip finds the package I can not import it in jupyter notebook - please see the screenshot that I've attached for the clarity. Describes the path to executable and the command prompt. Is something wrong with the kernel?

How can I fix this to use the redlines package in my kernel?

Screenshot from the situation

Share Improve this question edited 3 hours ago Miick asked 3 hours ago MiickMiick 32 bronze badges 6
  • Please provide your code/commands as code-formatted text instead of an image. – Anerdw Commented 3 hours ago
  • I always invoke pip via python -m pip. If funk stuff is happening in Jupyter, I always restart the kernel. Not saying these are solutions, but something to try. – JonSG Commented 3 hours ago
  • The more modern & convenient suggestion of what JohnSG is suggesting is handled by using the current best practice of using the modern magic commands when running in the notebook. You should be using %pip, e.g., %pip list to target things being run in notebook to the environment the kernel is running. The exclamation point does not do this. A lot of outdated material suggests an exclamation point with installs when it should be %pip install these days in modern Jupyter. This is nearly universal now, including working with JupyterLite and Google Colab. ... – Wayne Commented 3 hours ago
  • <continued> The second paragraph here goes into more details about why the exclamation point may lead to issues. This is the sort of thing that looks like you may be experiencing. See more about the modern %pip command here. – Wayne Commented 3 hours ago
  • @Wayne yes you are actually right it helped me to find out that the %pip list did not contained the redline package – Miick Commented 2 hours ago
 |  Show 1 more comment

1 Answer 1

Reset to default 1

The commands you want to run in your running Jupyter .ipynb file are:

%pip install redlines

Make a new cell and run that and then restart the kernel. (If it is a partcularly complex package sometimes you need to shut down all Jupyter and your browser and restart. And then wonce back in, do a hard browser refresh on the Jupyter notebook page. Some of the more complex installs involving controlling how things display, like ipympl, need more than just restart the kernel. Packages like pandas just needs restarting the kernel.)

And then to check that it installed to the correct environment, run in your notebook:

%pip list

The magic pip command variation was added in 2019 to ensure the install occurs in the environment where the kernel is running that backs the active notebook.

The exclamation point doesn't do that and can lead to issues.
You should be also using %pip list to see what is installed in the kernel that your notebook is using.

See more about the modern %pip install command here. The second paragraph here goes into more details about why the exclamation point may lead to issues.

本文标签: Can39t import python package to jupyter notebookStack Overflow