Lesson 2: Modules and pip in Python

 Lesson 2: Modules and Pip in Python

Overview

Here in this lesson, we will learn about modules and pip in Python. We will be getting to know, how modules make our wok a lot easier and how to install and use them. We wont be writing any code yet, but we will be doing some theory-practical today.

What are modules?

To understand modules, we may take help from the invention of wheel. Lets try to understand it with the help of a story.

Suppose there is a man, who is very smart, very intelligent and has a high capacity to think, but he is a bit dumb. He has taken upon himself the task of making a motorcycle which would be super fast and full of features. now he starts the work by inventing the wheel.

Now here, you may think that why is he inventing the wheel again and why is this story relevant to programming? Let me explain you. The man who is being talked about is you! Suppose you want to build something like a voice assistant like Alexa. Now you will probably be dividing the task into parts such as:
  • Making it speak
  • Making it hear
  • Add intelligence to act according to given command
Now hear me out, you need not spend hours on making it speak. There is already a programmer who has done that and has uploaded the code to help you. That is exactly what a module is. It is a piece of code which someone else wrote that you can use to make your work easy. 

What is pip?

Now that you know about modules and why they are useful, you just be wondering that where and how to get these. Well you need not worry as python has an inbuilt module installer. This is known as pip.

Installing some modules practically.

Now we will be installing some modules through pip and will be learning how to use them in actual code.

Installing the Ursina module

In order to install a module, we first need to access pip. Now pip is opened in command prompt. To open Command Prompt, open windows run by pressing Windows + R.
Now type cmd and press enter. Now do not get overwhelmed by the interface, it is not very complicated.
The syntax for installing a  python module is: pip install {module name}

In this case, you will be typing "pip install ursina" to install the ursina module.

The result may look something like this, if you get any error, consider rechecking for any typos. If that also doesn't solve the problem, don't get worried I will be mentioning some helpful links at the end to get it sorted.

Now you have successfully installed the Ursina module. You can find more modules on PyPi.

Using the module

You need not do this part, just understand what is being shown.

If you type in this code, you will have access to all the functions of the Ursina Module which you can use in the code:
from ursina import *


Solve "The term 'pip' is not recognized as the name of a cmdlet, function, or operable program"

Solve "pip is not recognized as an internal or external command, operable program or batch file"

Conclusion

All that I have written in this lesson may seem overwhelming or too much, but do not panic and go at your own pace, write any questions you have in the comments.
Thank You
Team CodeQuest

Comments

Popular posts from this blog

Lesson 1: Setting up Python and VS Code