How to run PIP Install command on Jupyter cell

Viewed 7922

I thought we could run PIP Install or PIP uninstall by running something like this on the Jupyter cell.

%pip install myPackage

But I am prompted for confirmation like this:

Proceed (y/n)?

How do I overcome this and run PIP in the cell?

5 Answers

Have you tried to install this way instead of using magic?

!pip install <package>

Generally this shouldn't prompt you to proceed.

BTW which package are you trying to install? I have tried both ways using !pip and %pip. Using %pip didn't ask me to proceed but asked me to restart kernel.

%pip install folium

Collecting folium
  Downloading https://files.pythonhosted.org/packages/c3/83/e8cb37afc2f016a1cf4caab8d22caf7fe4156c4c15230d8abc9c83547e0c/folium-0.12.1-py2.py3-none-any.whl (94kB)
Requirement already satisfied: requests in c:\users\by20064109\appdata\local\continuum\anaconda3\lib\site-packages (from folium) (2.22.0)
Requirement already satisfied: branca>=0.3.0 in c:\users\by20064109\appdata\local\continuum\anaconda3\lib\site-packages (from folium) (0.4.2)
Requirement already satisfied: numpy in c:\users\by20064109\appdata\local\continuum\anaconda3\lib\site-packages (from folium) (1.16.4)
Requirement already satisfied: jinja2>=2.9 in c:\users\by20064109\appdata\local\continuum\anaconda3\lib\site-packages (from folium) (2.10.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\by20064109\appdata\local\continuum\anaconda3\lib\site-packages (from requests->folium) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\by20064109\appdata\local\continuum\anaconda3\lib\site-packages (from requests->folium) (1.24.2)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\by20064109\appdata\local\continuum\anaconda3\lib\site-packages (from requests->folium) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\by20064109\appdata\local\continuum\anaconda3\lib\site-packages (from requests->folium) (2019.6.16)
Requirement already satisfied: MarkupSafe>=0.23 in c:\users\by20064109\appdata\local\continuum\anaconda3\lib\site-packages (from jinja2>=2.9->folium) (1.1.1)
Installing collected packages: folium
Successfully installed folium-0.12.1
Note: you may need to restart the kernel to use updated packages.

What about yes command instead of magic?

! yes| pip install myPackage
!pip install package_name

This is the standard way to install package in Jupyter notebook. But its better to make virtual environment and install all the necessary package in that virtual environment.

In case the prompt is related to the verification of an ssh key, you should add the host as trusted before running the %pip magic. For example for github

import os
os.system('ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts')
Related