How to install a third-party library in Jupyter Notebook
Published on Aug. 22, 2023, 12:16 p.m.
To install a third-party library in Jupyter Notebook, you can use the !pip
or !conda
command. Simply type the following command in a Notebook cell:
!pip install package-name
Or, if you are using Anaconda:
!conda install package-name
This will install the specified package from PyPI or the Anaconda repository. If you are not sure which package to install, you can look up relevant information online, or use the !pip search
or !conda search
command to find available packages. For example:
!pip search numpy
This will show a list of available packages related to numpy
, along with their descriptions and version numbers. Simply choose the package you need and install it using !pip install
or !conda install
.
Note that when installing packages, it is best practice to create a virtual environment or use a package management tool like conda to keep your project dependencies clean and organized. This will help avoid compatibility or dependency issues.
To export a list of installed third-party libraries in Jupyter Notebook
To export a list of installed third-party libraries in Jupyter Notebook, you can use the pip freeze
command. Simply type the command in a Notebook cell:
!pip freeze > requirements.txt
This will generate a file named requirements.txt
that contains a list of all installed Python packages, including the version number for each package. You can use this file to recreate your environment on another machine or share it with others.
Note that the > requirements.txt
part of the command redirects the output of pip freeze
to a file named requirements.txt
. You can change the file name and location as needed. Also, make sure to run this command in the same environment where you want to export the list of installed packages from.
You can also use the conda list
command if you are using Anaconda instead of pip freeze
. This will generate a similar list of installed packages specific to your conda environment.