Min menu

Pages

PIP in python

ConceptthePIPin python

In any project you build in Python you will most likely use ready-made classes and functions that other developers have built so you don't waste your time building everything from scratch.
In this lesson, you will learn how to easily include ready-made codes in your projects, relying on a tool calledPIPIn addition to doing it directly from the programPyCharm.

Now, since you are one of the millions of people who have decided to use the Python language in building their projects, this means that many developers have inevitably built ready-made codes and published them for free so that the rest of the developers can benefit from them while continuing to update these codes so that they remain compatible with the constant updates of the language Python and to address any gaps in these codes.

A developer who works professionally, usually builds the module in the same way you learned earlier. That is, it creates a Python file and inside it defines classes, functions, etc..
Of course, nothing prevents the developer from creating more than one module, or embedding another module in the module he is developing.

When a developer bundles the files he prepares into a single folder to make them easily downloadable and embeddable, this folder is said to be a bundle.(Package).
the toolPIPIt helps you to download and include any package you want in your projects with ease instead of having to search for them yourself on the Internet.



Technical information

Starting with version 3.4 of the Python language, the tool . has becomePIPIt is installed for you automatically during the installation of the Python language.
That is, if you are using this version or higher version of the Python language, you do not need to download it, but you can use it immediately.

In case you are using an old version of Python, this is the official pypa.io site to download this tool.
On this site you will also find the steps that must be followed to download and install it correctly on your computer.


Official site for downloading packages

On this site pypi.org you will find all the packages that you can install with the toolPIP.

 Find out if the toolPIPinstalled on the computer

To check whether the toolPIPInstalled on the computer, you can try to view the version of the installed version of it as follows:

  1. Open Command Prompt.

  2. write the commandpython -m pip --version

  3. Then click on the . buttonEnter


In the following example, we open a command prompt and type python -m pip --versionin it.
Note that it told us the tool version numberthePIPinstalled on the computer is9.0.1.

Command Prompt

> python -m pip --version
pip 9.0.1 from C:\Users\Mhamad\AppData\Local\Programs\Python\Python36-32\lib\site-packages (python 3.6)
>

As the toolPIPIt is on the computer, it means that we can use it to download any package we want.


note

In case you do not know how to open the Command Prompt, see the second paragraph of the second lesson, because we have already explained this matter in it.

Handling the toolPIPin python

In the beginning, before you think about dealing with this tool, make sure that your device is connected to the Internet because this tool downloads packages for you from the Internet.
Therefore, if you try to use it and your device is not connected to the Internet, you will see an error.

Now, to deal with the toolPIPThere are three basic methods:

  • You can use the command prompt provided in the operating system, which is not recommended for you as a beginner.

  • You can use the command prompt in the programPyCharm.

  • You can use the package manager in the programPyCharm.



Download a package using the command prompt in a programPyCharm

In the following example, we will download a package named camelcaseusing the command prompt in the programPyCharm.
To open the command prompt, click on the wordTerminalAs follows.

Now type pip install camelcaseand click on the button Enteras follows.

Any package you download will be placed in the foldersite-packageslocated in the folderExternal LibrariesAs follows.

Note: The alert that appears in yellow, means that there is a newer version of the toolPIP,And to update its version just write the commandpython -m pip install --upgrade pip.



Download a package using the package manager in a programPyCharm

To learn how to use the package manager in a programPyCharmTo install any package without having to type in commands, do the following:
Search YouTube forInstall Package in Pycharm.Then watch any video that appears in the search results.

Include the package installed in Python

After the package is installed, you will be able to embed it and use it like any other package on your device.


In the example we used the package camelcasewe just installed.
This package contains a class whose name CamelCase, which in turn contains its name function hump()that converts the first letter of each word to a capital letter.Capital Letter.

Example

Test.py
#camelcase Here we have included all package content
		  import camelcase
	  
		  # camelcase in the CamelCase package Here we have created an object from the class
		  c = camelcase.CamelCase()
	  
		  # it hump() Here we have defined the script that we are going to test the function
		  txt = "python is an easy language to learn."
	  
		  # To return a copy of the text in variable c from the hump() object here we called the function
		  # With the conversion of the first letter of each word to a capital letter. Then we print what the txt function will return
		  print(c.hump(txt))
	

We will get the following result when running.

Python is An Easy Language To Learn.

note

The way to install, embed and use the package camelcaseyou are using now applies to any other packages that we will include in the future.

 View all packages installed in the project in Python

To display all the packages you have installed that are already in the project, type the command pip listin the command prompt as follows.

How to view all packages installed in the project in Python

 Uninstall a package that was previously installed in Python

To uninstall any package you have previously installed, you can use the commandpip uninstall.

So, to uninstall the package camelcasewe downloaded earlier, we type the command pip uninstall camelcasein the command prompt and then click the buttonEnter.
We notice that it shows us the path of all the package files that will be uninstalled, and then tells us if we are sure we want to delete the package.
Now, to agree to cancel the package, we type the letter yand click the buttonEnter.

How to uninstall a package that was previously installed in Python