What is Pip in Python? | How to Install pip in Python

Introduction 

Writing code for developing an application is a tedious, thinking, and time-consuming task. A lot of time is invested in this process, and since it is an important initial stage to begin developing an application, it needs to be done. This is one point of view. The second point of view is that in many situations, some code that is being written for an application is already written previously by some application developers and is existing. Now the question is, is it possible that these codes can be reused directly instead of writing them from scratch. If so, then this will not only save a lot of time but also provide the most optimized version of the code. It will save us from doing unnecessary things.

Third-Party Tools achieve this. Though, Python has its standard library that provides useful modules right out of stock. But it is not feasible to have all the stuff in the Python that a developer needs while writing code. Python, like any other programming language, depends on other 3rd party libraries or packages which can be installed on the system through the Internet, and further using these things can play an important role in making our life greatly simpler. 

For this, a developer can fulfill his requirements by installing the required stuff from Python’s big collection of third-party modules.

Let’s take the example of Virtualenv, a third-party tool whose function is to isolate Python package installations from each other. This functionality becomes very useful and effective at the time when more than one project is running on the system. At this time, it’s a good practice to keep the package requirements separate. To do so, Virtualenv enables users to create a virtual Python environment for each project and install packages separately for each.

But, this question matters and needs to be discussed how these can be installed on the system for further use. In this regard, the name PIP strikes the mind, and this is where PIP comes into action. PIP is a unique tool that Python developers use to handle seamlessly downloading, installing, and managing these packages.

Let us now understand what exactly PIP is in Python.

We will start decoding PIP step by step and understand all the significant aspects of it.

What is pip in Python?

In Python, Pip is an essential and powerful tool that enables the Python user to manage distribution packages in Python. The Distribution Package is a versioned archive file in which Python packages, modules, and other resource files are collectively stored for the purpose of distributing a Release. End-users can download the archive file from the Internet and install it on their system. 

Pip is one of the most widely used package management tools.  Its main function is to install and manage the software packages that are written in Python and contained in Python Package Index (PyPi).

Pip, being a recursive acronym, stands for either “Pip Installs Packages” or “Pip Installs Python,” and alternatively, it stands for Preferred Installer Program.

Pip was developed by Ian Bicking, a software engineer from Minneapolis. The first version of pip was released on 04th Apr 2011. Python 2.7.9 and later distributions have pip preinstalled. Pip 22.0.4. pip install pip is the latest version, and it was released on 06th March 2022.

How to Install Pip in Python?

To work effectively and efficiently for an application, it must be installed properly on the system where it will be working. Then only a proper utilization of it and desired results from it can be achieved.

Usually, in the case of working in a virtual environment or the latest version of Python, pip is found automatically pre-installed.

To check pip is available on the system, run the following command in your console:

Input:

$ pip --version

If you get the output like below:

pip 20.2.3 from c:\python39\lib\site-packages\pip (python 3.9)

Displaying the current pip version and the location and version of Python, then pip is installed in your system.

Otherwise, download pip from the site pypi.org and install it on the system. pip can be installed in two ways:

1.  ensurepip

2.  get-pip.py

How to install pip in different platforms will be discussed ahead in this article.

How to use pip in Python?

In Python, pip can be operated from the command line or a shell. Once pip is installed, it can be used directly along with some arguments. The basic syntax of pip in python is –

py -m pip <pip arguments>

Using the latest Python interpreter installed on the system, py -m pip executes pip.

So, here type “pip” followed by some arguments like install some package —

Example:

py -m pip install SomePackage

A Glance On The Various Usage Of pip In Python: 

1. Basic Package Installations

Install command is used to install any package using pip in python. The basic syntax is:

pip install <package-name>

For example, to install requests using pip – enter the following command:

pip install requests

After this, the output will be similar to:

Collecting requests

Using cached requests-2.26.0-py2.py3-none-any.whl (62 kB)

Requirement already satisfied: charset-normalizer~=2.0.0; python_version >= “3” in c:\python39\lib\site-packages (from requests) (2.0.7)

Requirement already satisfied: idna<4,>=2.5; python_version >= “3” in c:\python39\lib\site-packages (from requests) (2.10)

Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\python39\lib\site-packages (from requests) (1.26.6)

Requirement already satisfied: certifi>=2017.4.17 in c:\python39\lib\site-packages (from requests) (2021.5.30)

Installing collected packages: requests

Successfully installed requests-2.26.0

Thereafter, the package will be installed, and it can be imported and used in the code easily.

By default, pip installs the package in the Python installation folder : 

<installation_folder_name>\python39\lib\site-packages.

In the case, pip is used with virtualenv, it will generally install packages in the path:

<virtualenv_name>/lib/<python_ver>/site-packages

Moreover, the installation path of the packages can always be checked using:

pip show <package-name>

Example:

C:\Users\deepa>pip show google

Output:

Name: google

Version: 3.0.0

Summary: Python bindings to the Google search engine

Home-page: 

HTTP://breakingcode.wordpress.com/

Author: Mario Peter

Author-email: mpeter@gmail.com

License: UNKNOWN

Location: C:\python39\lib\site-packages

Required: beautifulsoup4

Require-by:

2. Specifying Package Version with pip

In Python, the pip install command always installs the latest version of a package. In case, instead of the latest one, there is a need to install a specific version of the package, then the name of the required version may directly be specified with the pip command syntax:

pip install <package-name==version>

As a result, the package with the mentioned version will be installed.

For example:

pip install sciPy==1.7.2

Output:

Collecting sciPy==1.7.2

Downloading scipy-1.7.2-cp39-cp39-win_amd64.whl (34.3 MB) 34.3 MB 371 kB/s

Requirement already satisfied: numpy<1.23.0,>=1.16.5 in c:\python39\lib\site-packages (from sciPy==1.7.2) (1.21.4)

Installing collected packages: sciPy

Successfully installed sciPy-1.7.2

As a result, the above command will install the package named ‘sciPy’ of the specified version on the system in the python installation folder. If using a virtual environment, then it will install here:

<virtualenv_name>/lib/<python_ver>/site-packages

3. Displaying Package information with pip

The pip show command is used to display the complete information about a package installed using pip in Python.

Suppose the python package requests are installed using the following command: 

pip install requests

Now to check the complete information about the package, the pip show command mentioned below can be used:

pip show requests

A detailed summary of the package will be displayed on the screen, like:

Name: requests

Version: 2.26.0

Summary: Python HTTP for Humans.

Home-page: https://requests.readthedocs.io

Author: Kenneth Reitz

Author-email: me@kennethreitz.org

License: Apache 2.0

Location: c:\python39\lib\site-packages

Requires: charset-normalizer, urllib3, idna, certifi

Required-by:

This command helps to know the location of a package, version type, requirements/dependencies, and many other things.

4. List Installed Packages with pip

The pip list command is used to list all the packages installed in the system or the current python environment.

Run this command in the command line of the system:

pip list 

As a result, a list of all available packages on the system will generate:

beautifulsoup4     4.9.3

certifi            2021.5.30

chardet            4.0.0

charset-normalizer 2.0.7

google             3.0.0

idna               2.10

numpy              1.21.4

pip                20.2.3

pyodbc             4.0.31

requests           2.26.0

scipy              1.7.2

selenium           3.141.0

setuptools         49.2.1

soupsieve          2.2.1

urllib3            1.26.6

5. Uninstall Packages with pip

A package can be uninstalled using pip.

We can uninstall a with the pip uninstall command. See example:

pip uninstall sciPy

By running this command, sciPy will be uninstalled from the current python environment. The following will appear on the screen:

Found existing installation: scipy 1.7.2

Uninstalling scipy-1.7.2:

  Would remove:

    c:\python39\lib\site-packages\scipy-1.7.2.dist-info\*

    c:\python39\lib\site-packages\scipy\*

Proceed (y/n)? y

  Successfully uninstalled scipy-1.7.2

Note: The packages installed as dependencies with this package will not be removed. For example, “numpy,” which is a dependency for sciPy, will not be uninstalled.

6. Search Packages with pip

Earlier in Python, using pip in Python through the pip search command, it was possible to search for any package, but now the pip search command is permanently banned by python.org.

The reason behind this is the experience of “hundreds of thousands of search calls per hour” for 100 days, and the XMLRPC API is already deprecated through which these search calls were made.

Note: Now, a search for any package directly can be done on pypi.org.

7. Listing Additional Packages with pip

The Python pip freeze command is used for listing down all the packages that are installed in the system. It informs:

  • The modules/packages installed using pip install in the current environment
  • The versions of these modules are currently installed in the system.

Run the following command in the console:

pip freeze

Output:

beautifulsoup4==4.9.3

certifi==2021.5.30

chardet==4.0.0

charset-normalizer==2.0.7

google==3.0.0

idna==2.10

numpy==1.21.4

pyodbc==4.0.31

requests==2.26.0

scipy==1.7.2

selenium==3.141.0

soupsieve==2.2.1

urllib3==1.26.6

The freeze command dumps a list of all the packages and their versions into the standard output.

8. Using Requirement Files with PIP

First, let’s understand the what the purpose of the requirements.txt file in a code is:

Requirements.txt files are generated and shared to make other developers comfortable with installing the correct versions of the required Python libraries or packages to run the Python code which has already been written.

To generate the requirements.txt file, just run this command:

pip freeze > requirements.txt

After the execution of this code, a requirements.txt file will generate into the working directory.

Now, anyone can simply run the below-mentioned command to get all dependencies installed into their system.

pip install -r requirements.txt

Once these dependencies are installed, then you can go ahead.

9. Listing Outdated Packages with pip

The pip list –outdated command can be used to list all the outdated packages in python.

Example:

pip list --outdated

The output contains the packages along with their current & latest versions available —

Package  Version     Latest Type

beautifulsoup4    4.9.3    4.10.0    

wheel

certifi    2021.5.30    2021.10.8    

wheel

idna    2.10    3.3    wheel

pip    20.2.3    21.3.1    wheel

pyodbc    4.0.31    4.0.32    wheel

selenium    3.141.0    4.0.0    

wheel

setuptools    49.2.1    59.1.1    wheel

soupsieve    2.2.1    2.3.1    wheel

urllib3    1.26.6    1.26.7    wheel

After having understood the major usage, let us now learn how to install pip on different platforms.

Installing PIP on different OS

Let us know the various ways to install pip:

1. How to Install pip on Windows:

Follow the given steps to install pip in Windows:

First, download the get-pip.py installer script.

Simply Right-click on the link -> save as, and save it in any specific folder inside the local machine. 

Navigate to a terminal/command prompt, cd to the folder containing the get-pip.py file

Run the below command

C:> py get-pip.py

This will install pip in your system.

Note: get-pip.py is a Python script. It uses some bootstrapping logic for the installation of pip.

2. How to Install PIP on Mac:

The installation procedure is just as in Windows. Follow the same steps to install pip on Mac using the get-pip.py.

Type command:

$ python get-pip.py

This will install pip in the system. More details about this script can be found in the pypa/get-pip readMe.

There is an alternative way to install pip is through sudo / brew:

Run the below-mentioned command:

$ sudo easy_install pip

Or through brew:

brew install python

The latest version of Python will be installed, with pip already installed in it. If not, then re-link Python using the following Terminal command:

brew unlink python && brew link python

3. How to Install PIP on Linux

If python is already installed in the Linux system, then pip can be installed using the system’s package manager.

Although the get-pip.py script is used to install pip, some more preferable ways are mentioned below:

1. Advanced Package Tool :

  • Python 2.x
$ sudo apt-get install python-pip
  • Python 3.x
sudo apt-get install python3-pip

2. Pacman Package Manager:

  • Python 2.x
sudo pacman -S python2-pip
  • Python 3.x
sudo pacman -S python-pip

3. Yum Package Manager:

  • Python 2.x
sudo yum upgrade python-setuptools
sudo yum install python-pip python-wheel
  • Python 3.x
sudo yum install python3 python3-wheel

This will install pip in the system.

How to Install pip on Raspberry Pi?

In the system using Raspberry Jessie, pip comes installed by default. If using an older version and pip is not there, then pip can be installed using the following commands:

  • Python 2.x:
sudo apt-get install python-pip
  • Python 3.x:
sudo apt-get install python3-pip

How to Upgrade pip for Python?

Upgrading versions is an important activity to mitigate vulnerabilities. Every update helps to fix bugs and security holes frequently.

pip in Python can be upgraded by:

For Windows:

python -m pip install -U pip

For Linux/Mac/Raspberry Pi:

pip install -U pip

Note: For some versions of Linux and Raspberry Pi,  pip3 may be required for the installation.

Downgrading Packages with pip

In Python, downgrading pip is simple. But, the version into which the pip is being downgraded needs to be specified.

Type the below command in the command line:

$ python -m pip install pip==19.2

Mention a version of choice while downgrading. It will downgrade to that version.

Alternatives to pip

Several alternatives are available to pip which are worth trying. Let us learn some of them.

1. Conda:  It is an open-source package manager.

It is useful to find and install python packages and their dependencies very easily.

The conda package is included in Anaconda.

2. Pipenv: It is helpful to bring the best of all packaging worlds to Python.

It merges the virtual environment and package management into a single tool.

It automatically adds/removes packages from Pipfile at the time of installing/uninstalling packages.

3. Poetry: It makes package version management more simple.

Poetry helps to declare, manage and install dependencies of Python projects.

It supports Python 3.6+.

Important Terminologies 

Before concluding this article, I feel it necessary that you go through the following terminologies, which are explained to make you aware because these are commonly used in Python, and when you work for developing any application in Python, that time you will encounter these.

1.  Binary Distribution

A particular type of Built Distribution in which compiled extensions are contained.

2.  Built Distribution

It is a Distribution format where files and metadata are stored that can be moved to the targeted location for installation for further use. A wheel can be taken as an example. It is such a type of format. The wheel is such a format.

3.  Wheel

A wheel is a type of built distribution. The wheel is a ready-to-install format that allows users to skip the build stage, whereas, in the case of distutil source distributions, it is needed to be followed.

4. Distutil Distribution Package 

The main purpose of the distutil distribution package is to provide support for the building and installation of such new additional modules that are not a part of Python into a Python installation. The new modules may be anything, like codes written 100% in pure Python or extension modules in which codes are written in C, or a collection of Python packages in which codes in the modules are written in both Python and C.

5. Python Egg

A Python egg is a type of logical structure where the release of a specific version of a Python project, including its code, resources, and metadata, is contained. Multiple formats are there that can be used to encode a Python egg physically, and other formats can be developed.

6. Extension Module

It is a module that is written in a low-level language, usually in C and sometimes in C++. The reason is that an API provided by CPython works with Python objects targeted at C. A single dynamically loadable pre-compiled files, like a .so file (a shared object) for Python extensions on Unix, a .pyd file for Python extensions on Windows, or a Java class file for Jython extensions, are typically contained in it.

7. Known Good Set (KGS)

It can be defined as a set of distributions at specified versions which are compatible with each other. Typically a test suite will be run that passes all tests before a specific set of packages is declared a known good set. This term is commonly used by frameworks and toolkits which are composed of multiple individual distributions.

8. Import-Package

It is a Python module that contains other modules or, recursively, other packages.

It is an import package and is usually referred to with the single word “package.” In this guide, we will use its expanded term to have more clarity and prevent confusion with a Distribution Package because the Distribution Package is also usually called a “package.”

9. Module

The basic unit that facilitates code reusability in Python. It exists in one of two types, either Pure Module or Extension Module.

10. Package Index

It can be defined as a web-based repository of distributions that automates package discovery and consumption.

11. Per Project Index

A non-canonical Package Index is specified by a single Project as the index preferred or required to resolve that project’s dependencies.

12. Pure Module

This module is purely written in Python and contained in a single file (.py) – pyc or .pyo files possibly associated.

13. Python Packaging Authority (PyPA)

In Python packaging, many of the relevant projects are maintained by a working group known as PyPA. Their work includes maintaining a site at pypa.io, hosting projects on GitHub and Bitbucket, and discussing issues on the distutils-sig mailing list and the Python Discourse forum.

14. Python Package Index (PyPI)

In Python, PyPI is the default Package Index. It is an open forum where all Python developers can consume and distribute their distributions.

15. pypi.org

The domain name for the Python Package Index (PyPI) is pypi.org. It was developed for the replacement of the legacy index domain, pypi.python.org, in 2017. It is powered by Warehouse.

16. pyproject.toml

The tool-agnostic Project specification file. Defined in PEP 518.

17. Release

A release can be explained as a snapshot of a project at a particular point in time. It is denoted by a version identifier.

In a release, there may be the publishing of multiple Distributions. For example, if version 1.0 of a project is released, it may have both a source distribution format and a Windows installer distribution format.

18. Requirement

A specification for a package to be installed. Pip is a PYPA-recommended installer that allows various forms of specification that can all be considered a “requirement.” To get more information, see the pip install reference.

Conclusion

So, finally, we reached the end of this tutorial with a brief idea of pip. Let us just refresh what we learned throughout the tutorial in short.

Pip acts as a package manager, and its work is to install/manage packages/dependencies.

The extensive standard library of Python is published in Python Package Index (PyPI), and pip allows developers to install them in their environment.

We also learned how to install pip in different OS (Windows/Mac/Linux/Raspberry).

We have also learned various features of pip in Python, like installing/ uninstalling/ listing/ upgrading/ downgrading packages.

Finally, we found some alternatives to pip in Python.


Original article source at: https://www.mygreatlearning.com

#python 

What is GEEK

Buddha Community

What is Pip in Python? | How to Install pip in Python
Ray  Patel

Ray Patel

1619510796

Lambda, Map, Filter functions in python

Welcome to my Blog, In this article, we will learn python lambda function, Map function, and filter function.

Lambda function in python: Lambda is a one line anonymous function and lambda takes any number of arguments but can only have one expression and python lambda syntax is

Syntax: x = lambda arguments : expression

Now i will show you some python lambda function examples:

#python #anonymous function python #filter function in python #lambda #lambda python 3 #map python #python filter #python filter lambda #python lambda #python lambda examples #python map

Shardul Bhatt

Shardul Bhatt

1626775355

Why use Python for Software Development

No programming language is pretty much as diverse as Python. It enables building cutting edge applications effortlessly. Developers are as yet investigating the full capability of end-to-end Python development services in various areas. 

By areas, we mean FinTech, HealthTech, InsureTech, Cybersecurity, and that's just the beginning. These are New Economy areas, and Python has the ability to serve every one of them. The vast majority of them require massive computational abilities. Python's code is dynamic and powerful - equipped for taking care of the heavy traffic and substantial algorithmic capacities. 

Programming advancement is multidimensional today. Endeavor programming requires an intelligent application with AI and ML capacities. Shopper based applications require information examination to convey a superior client experience. Netflix, Trello, and Amazon are genuine instances of such applications. Python assists with building them effortlessly. 

5 Reasons to Utilize Python for Programming Web Apps 

Python can do such numerous things that developers can't discover enough reasons to admire it. Python application development isn't restricted to web and enterprise applications. It is exceptionally adaptable and superb for a wide range of uses.

Robust frameworks 

Python is known for its tools and frameworks. There's a structure for everything. Django is helpful for building web applications, venture applications, logical applications, and mathematical processing. Flask is another web improvement framework with no conditions. 

Web2Py, CherryPy, and Falcon offer incredible capabilities to customize Python development services. A large portion of them are open-source frameworks that allow quick turn of events. 

Simple to read and compose 

Python has an improved sentence structure - one that is like the English language. New engineers for Python can undoubtedly understand where they stand in the development process. The simplicity of composing allows quick application building. 

The motivation behind building Python, as said by its maker Guido Van Rossum, was to empower even beginner engineers to comprehend the programming language. The simple coding likewise permits developers to roll out speedy improvements without getting confused by pointless subtleties. 

Utilized by the best 

Alright - Python isn't simply one more programming language. It should have something, which is the reason the business giants use it. Furthermore, that too for different purposes. Developers at Google use Python to assemble framework organization systems, parallel information pusher, code audit, testing and QA, and substantially more. Netflix utilizes Python web development services for its recommendation algorithm and media player. 

Massive community support 

Python has a steadily developing community that offers enormous help. From amateurs to specialists, there's everybody. There are a lot of instructional exercises, documentation, and guides accessible for Python web development solutions. 

Today, numerous universities start with Python, adding to the quantity of individuals in the community. Frequently, Python designers team up on various tasks and help each other with algorithmic, utilitarian, and application critical thinking. 

Progressive applications 

Python is the greatest supporter of data science, Machine Learning, and Artificial Intelligence at any enterprise software development company. Its utilization cases in cutting edge applications are the most compelling motivation for its prosperity. Python is the second most well known tool after R for data analytics.

The simplicity of getting sorted out, overseeing, and visualizing information through unique libraries makes it ideal for data based applications. TensorFlow for neural networks and OpenCV for computer vision are two of Python's most well known use cases for Machine learning applications.

Summary

Thinking about the advances in programming and innovation, Python is a YES for an assorted scope of utilizations. Game development, web application development services, GUI advancement, ML and AI improvement, Enterprise and customer applications - every one of them uses Python to its full potential. 

The disadvantages of Python web improvement arrangements are regularly disregarded by developers and organizations because of the advantages it gives. They focus on quality over speed and performance over blunders. That is the reason it's a good idea to utilize Python for building the applications of the future.

#python development services #python development company #python app development #python development #python in web development #python software development

Art  Lind

Art Lind

1602968400

Python Tricks Every Developer Should Know

Python is awesome, it’s one of the easiest languages with simple and intuitive syntax but wait, have you ever thought that there might ways to write your python code simpler?

In this tutorial, you’re going to learn a variety of Python tricks that you can use to write your Python code in a more readable and efficient way like a pro.

Let’s get started

Swapping value in Python

Instead of creating a temporary variable to hold the value of the one while swapping, you can do this instead

>>> FirstName = "kalebu"
>>> LastName = "Jordan"
>>> FirstName, LastName = LastName, FirstName 
>>> print(FirstName, LastName)
('Jordan', 'kalebu')

#python #python-programming #python3 #python-tutorials #learn-python #python-tips #python-skills #python-development

Art  Lind

Art Lind

1602666000

How to Remove all Duplicate Files on your Drive via Python

Today you’re going to learn how to use Python programming in a way that can ultimately save a lot of space on your drive by removing all the duplicates.

Intro

In many situations you may find yourself having duplicates files on your disk and but when it comes to tracking and checking them manually it can tedious.

Heres a solution

Instead of tracking throughout your disk to see if there is a duplicate, you can automate the process using coding, by writing a program to recursively track through the disk and remove all the found duplicates and that’s what this article is about.

But How do we do it?

If we were to read the whole file and then compare it to the rest of the files recursively through the given directory it will take a very long time, then how do we do it?

The answer is hashing, with hashing can generate a given string of letters and numbers which act as the identity of a given file and if we find any other file with the same identity we gonna delete it.

There’s a variety of hashing algorithms out there such as

  • md5
  • sha1
  • sha224, sha256, sha384 and sha512

#python-programming #python-tutorials #learn-python #python-project #python3 #python #python-skills #python-tips

How To Compare Tesla and Ford Company By Using Magic Methods in Python

Magic Methods are the special methods which gives us the ability to access built in syntactical features such as ‘<’, ‘>’, ‘==’, ‘+’ etc…

You must have worked with such methods without knowing them to be as magic methods. Magic methods can be identified with their names which start with __ and ends with __ like init, call, str etc. These methods are also called Dunder Methods, because of their name starting and ending with Double Underscore (Dunder).

Now there are a number of such special methods, which you might have come across too, in Python. We will just be taking an example of a few of them to understand how they work and how we can use them.

1. init

class AnyClass:
    def __init__():
        print("Init called on its own")
obj = AnyClass()

The first example is _init, _and as the name suggests, it is used for initializing objects. Init method is called on its own, ie. whenever an object is created for the class, the init method is called on its own.

The output of the above code will be given below. Note how we did not call the init method and it got invoked as we created an object for class AnyClass.

Init called on its own

2. add

Let’s move to some other example, add gives us the ability to access the built in syntax feature of the character +. Let’s see how,

class AnyClass:
    def __init__(self, var):
        self.some_var = var
    def __add__(self, other_obj):
        print("Calling the add method")
        return self.some_var + other_obj.some_var
obj1 = AnyClass(5)
obj2 = AnyClass(6)
obj1 + obj2

#python3 #python #python-programming #python-web-development #python-tutorials #python-top-story #python-tips #learn-python