Installing and importing modules and libraries

What are modules?

Modules are python files that contain at least one class or function and you can import them and they usually have feature that let you do specific stuff.

Since classes are not beginner stuff , I won't cover them .

What about libraries?

Unlike C or C++, the term library does not have any specific contextual meaning , but it usually means a collection of modules.

Examples of libraries that I consider useful

Pyautogui is a beginner-frendly library that lets you control the keyboard and mouse clicks and position and a lot more by coding in python. It also includes some basic image recognition. It's a good library for basic bots or automate stuff that's really repetitive. You should check it out if you wanna experience a low level type of bots and see what you can do with it. https://pyautogui.readthedocs.io/en/latest/introduction.html

Opencv is a image recognition and manipulation library that let's you recognize stuff on the screen more accuratly or write or read images and modifying them , good when you have to modify images on a large scale and the same way. It can also draw , match template, display images as well as video [since videos are a series of images] https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_image_display/py_image_display.html

Time is a built-in library that you don't need to install to use , it has really useful feature for software like time.sleep(<seconds>) or time.time() which displays UNIX time, you can also use make stopwatches and monitor how long your program takes to run.

Keras is a beginner-frendly library for machine learning , it runs tensorflow backend which is a library made by google to help development of AIs , Keras is better for a beginner since tensorflow doesn't have good documentation. Also to use keras you still need to read some other tutorials about it , but that's the easiest way to get into machine learning so far

How to install them and use 'em ?

You can do it using anaconda [I can't get it working on my system so we won't do that] . You can use pycharm package manager if your interpreter is in a virtual environment and if you did follow along the tutorial series [the first lesson to be more precise] you probably don't have a virtual interpreter so you can't use package manager [it has some problems installing important packages like cv2 ]

PIP is the way I do it and for unknown packages that can't be installed directly from PIP I use git clone to get them [if you are looking to do relative big projects you should google on how to use GIT since I won't cover it]

Pip is built-in so you don't have to install it if you've done a default installation. I'll keep it simple , to install a package just open a command prompt [by going to search and typing CMD then press enter] and type pip install <package_name> and the pip will try to find it and if it finds it , it will try to install it and if you have the requirements of the package it will install.

How to import them?

To import an entire module/library you do at the start of your file import <package_name>

To import just a function or object from the library just do from <package_name> import <function_or_object>

You can also import functions and objects from the python files in the same directory , this includes the files you've made [also import <package> will also run the package and if you import one of your own files you might as well run it unless you use a special method I won't get into]

Last updated

Was this helpful?