Search code examples
pythonpython-module

What are ways of using external modules and libraries in Python?


The book "Learning Python" by Mark Lutz states that in Python one can use various types of external modules, which include .py files, .zip archives, C/C++ compiled libraries and others. My question is, how does one usually handle installation of each type of module? For example, I know that to use a .py module, I simply need to locate it with import. What about something like .dll or .a? Or for example, I found an interesting library on GitHub, which has no installation manual. How do I know which files to import? Also, are there any ways of installing modules besides pip?


Solution

  • The answer depends on what you want to do. You can use Ninja for example to use C++ modules and cython for C and there are various packages for almost any type of compiled code. You can install packages via pip using the pypi package repository or by using cloned repositories that have a setup.py file inside. Any other python based repo can be imported either by a custom build script (that they will provide) or by directly importing the relevant Python files. This will require you the dive into the code and check what are the relevant files.