Thursday, 9 December 2021

Write a program to demonstrate working with installing and loading packages in PYTHON

Jupyter Notebook is an open-source web application that is used to create and share documents that contain data in different formats which includes live code, equations, visualizations, and text. Uses include data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more.

Jupyter has support for over 40 different programming languages and Python is one of them. Python is a requirement (Python 3.3 or greater, or Python 2.7) for installing the Jupyter Notebook itself.

In Jupyter everything runs in cells. It gives options to change the cell type to markup, text, Python console, etc. Within the Python IPython console cell, jupyter allows Python code to be executed.
Installing Python Library in Jupyter
Using ! pip install

To install Python libraries, we use pip command on the command line console of the Operating System. The OS has a set of paths to executable programs in its so-called environment variables through which it identifies directly what exactly the pip means. This is the reason that whenever pip command can directly be run on the console.

In Jupyter, the console commands can be executed by the ‘!’ sign before the command within the cell.

 we can install any package via jupyter and it will run it directly in the OS shell.


! pip install [package_name]

Example: Let’s install NumPy using Jupyter.

But using this method is not recommended because of the OS behavior. This command executed on the current version in the $PATH variable of the OS. So in the case of multiple Python versions, this might not install the same package in the jupyter’s Python version. In the simplest case it may work.

Using sys library

To solve the above-mentioned problem, it is recommended to use sys library in Python which will return the path of the current version’s pip on which the jupyter is running. sys.executable will return the path of the Python.exe of the version on which the current Jupyter instance is


import sys
!{sys.executable} -m pip install [package_name]




Post a Comment

Note: only a member of this blog may post a comment.

Find Us On Facebook

Computer Basics


C Programming


Java Tutorial


Data Structures


MS Office


Database Management