Python libraries and packages »

My Coding > Programming language > Python > Python libraries and packages

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
pip list
pip list
The beginning of output from pip list command
Original image: 649 x 243

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


pip freeze
pip freeze
pip freeze
The beginning of output from pip freeze command
Original image: 1257 x 331

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


pip show wordcloud
pip show wordcloud
pip show wordcloud
The deailed information about installed package ‘wordcloud’
Original image: 766 x 269

Check installed libraries with conda

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


conda list
conda list
conda list
The beginning of output from conda list command
Original image: 995 x 333

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

Last 10 artitles


9 popular artitles

© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit.