Python is a relatively simple programming language that’s not too difficult to pick up. Some of Python’s functionality isn’t included in the main Python libraries, instead, it’s included via optional modules. You can include any required modules in your Python code with a single line command. Not all modules are installed by default however, sometimes you will have to download the module first to be able to use it. Python has a package manager to help install any modules you don’t have, just like “apt-Get” is used to install Linux packages.
The Python package manager is called PIP. PIP is short for either “Preferred Installer Program” or “Pip Installs Packages” depending on personal preference. If PIP isn’t installed by default on your Linux system you can install it from apt with the package name “python-pip-whl” and “python3-pip”.
Note: Python 2.7 and Python 3 have different versions of PIP. You don’t necessarily need both, but they can only affect packages for their respective python environments. The PIP and PIP3 commands are interchangeable.
How to install a python module with PIP
The first step of installing a package with PIP is to work out what the package is called. To do so you need to use the search function with the command “pip3 search [search term]”. For example, you can type “pip3 search md5” to search for modules relating to the md5 hashing algorithm. The package name is on the left, with a short description listed on the right.To install a module you’ve found, type the command “pip3 install [package name]” and pip will automatically collect and install the files you need. For example, the command “pip3 install md5utils” will install the “md5utils” module in python3.
To be able to use a downloaded module in python you need to import the module into your code. To do so, you need to include the line “import [module name]”, for example, “import md5utils”. The import statement should be one of the first lines in your code.
Did this help? Let us know!