.. _chshpipinstallrst: =========================== Pip install from a notebook =========================== .. only:: html **Links:** :download:`notebook `, :downloadlink:`html `, :download:`PDF `, :download:`python `, :downloadlink:`slides `, :githublink:`GitHub|_doc/notebooks/cheat_sheets/chsh_pip_install.ipynb|*` How to install a module from a notebook. .. code:: ipython3 from jyquickhelper import add_notebook_menu add_notebook_menu() .. contents:: :local: 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: .. code:: ipython3 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 .. code:: ipython3 pip_main("install -q qgrid".split()) .. parsed-literal:: 0 Interesting options ------------------- Avoid installing dependencies ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: ipython3 try: pip_main("install -q qgrid --no-deps".split()) except Exception as e: print(e) Upgrade ~~~~~~~ .. code:: ipython3 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: .. code:: ipython3 pip_main("install -q qgrid --upgrade --no-deps --no-cache-dir".split()) .. parsed-literal:: 0 For the hackathon… ------------------ ``pip_main("install pyquickhelper pyensae ensae_projects --upgrade --no-deps --no-cache-dir".split())``