Python libraries and packages

Python offer a lot of different libraries and packages for working with different data and tasks. It is a high chance that almost all basic task you need to solve, already solved in one of the libraries, so it is better to check them first.

How to use Python libraries

How to install Python library

Many basic libraries are installed together with Python core package, but some of them need to be installed additionally

To install library with pip use:


pip install 

To install library with conda, use:


conda install -c conda-forge 

Check installed libraries with pip

It is very easy to check, what libraries of packages you already have


pip list
The beginning of output from pip list command
pip list

The beginning of output from pip list command

To output installed packages in requirements format, use parameter freeze for pip


pip freeze
The beginning of output from pip freeze command
pip freeze

The beginning of output from pip freeze command

The detailed information about installed package it is possible to fetch with pip command with option ‘show’


pip show wordcloud
The deailed information about installed package ‘wordcloud’
pip show wordcloud

The deailed information about installed package ‘wordcloud’

Check installed libraries with conda

Run conda with parameter list to receive full list of installed packages for Python


conda list
The beginning of output from conda list command
conda list

The beginning of output from conda list command

How to use Python libraries

There are three main ways of importing Python libraries into your script.

You can import library as it is and use later full name ogf this library


import random

It is possible to shorten name of the library for more simple coding


import numpy as np

Also, it is possible to import only one or few functions from library and use they names


from random import gauss
from numpy import arccosh, arcsin

If you’ve import library, you can have a list of all functions, variables and methods defined in this library


import random
print(dir(random)) # ['BPF', 'LOG4', 'NV_MAGICCONST', 'RECIP_BPF', 'Random', …


Published: 2021-10-04 11:32:08
Updated: 2021-10-04 11:45:46