Pip install from a notebook

How to install a module from a notebook.

In [1]:
from jyquickhelper import add_notebook_menu
add_notebook_menu()
Out[1]:
run previous cell, wait for 2 seconds

Update or install a module from the notebook

Running pip install from the command line requires to be in the right folder. And sometimes, several python installations interfere between each others. Why doing it from the notebook itself:

In [2]:
try:
    # pip >= 19.3
    from pip._internal.main import main as pip_main
except Exception:
    try:
        # pip >= 10.0
        from pip._internal import main as pip_main
    except Exception:
        # pip < 10.0
        from pip import main as pip_main
In [3]:
pip_main("install -q qgrid".split())
Out[3]:
0

Interesting options

Avoid installing dependencies

In [4]:
try:
    pip_main("install -q qgrid --no-deps".split())
except Exception as e:
    print(e)

Upgrade

In [5]:
try:
    pip_main("install -q qgrid --upgrade --no-deps".split())
except Exception as e:
    print(e)

No cache

By default, pip uses cached version. So, if a module has just been updated, pip might choose to use the previous version. To tell it not to do so:

In [6]:
pip_main("install -q qgrid --upgrade --no-deps --no-cache-dir".split())
Out[6]:
0

For the hackathon...

pip_main("install pyquickhelper pyensae ensae_projects --upgrade --no-deps --no-cache-dir".split())

In [7]:
 
In [8]: