Managing Packages with pip in Python
Hello, python enthusiasts, today’s learning topic is ‘Managing Packages with pip in Python’.
- PACKAGE: A package consists of all the required files you need for that module.
- pip: Pip works as a python package manager and it comes along with the Python binary installers.
- MODULES: Python code libraries required in your project are called modules.
Introduction to pip:
‘pip’ the standard package manager also referred to as the preferred installer program.
Using pip we can perform the following functions:
- Install a package.
- Upgrade a package.
- Remove a package.
pip installs packages from the Python Package Index, or we may browse through the pip’s limited search feature.
Also, take a quick look at learning a few concepts on, Virtual Environment in python which will help in ease of use of this python package manager.
It is highly recommended to use a virtual environment as one Python installation is unable to meet the requirements of every application. Suppose if an application ‘XYZ’ needs version 1.0 of a particular module but application ‘ZMW’ needs version 2.0, then the requirements of both these applications are conflicting and installing either version 1.0 or 2.0 consequently leaves one application unable to run.
Hence, we use the virtual environment in Python to resolve this issue.
Some operations performed using pip in Python:
- Checking if pip is installed:
We use the following command to check if pip is installed on the system or not.
Firstly, traverse to the directory of your Python Installation and move into the ‘Scripts’ folder. Then proceed with the command as follows:
C:\Users\Tirthesh Pawar\AppData\Local\Programs\Python\Python38\Scripts>pip --version
If pip is installed properly on your system the following line gets generated as the output on your terminal.
pip 19.2.3 from c:\users\tirthesh pawar\appdata\local\programs\python\python38\lib\site-packages\pip (python 3.8)
Supposedly, pip is not installed on your system then you can visit this link: https://pypi.org/project/pip/
- Downloading a package using pip:
Downloading a package in pip is not a daunting task, we can simply write a one-liner command as follows to download a particular package as follows:
C:\Users\Tirthesh Pawar>pip install camelcase
Collecting camelcase Downloading https://files.pythonhosted.org/packages/24/54/6bc20bf371c1c78193e2e4179097a7b779e56f420d0da41222a3b7d87890/camelcase-0.2.tar.gz Building wheels for collected packages: camelcase Building wheel for camelcase (setup.py) ... done Stored in directory: C:\Users\Tirthesh Pawar\AppData\Local\pip\Cache\wheels\b1\fe\08\84d2143069bc44c20127c38cc1bf202332319b3da7315ca766 Successfully built camelcase Installing collected packages: camelcase Successfully installed camelcase-0
You can find many more packages to tailor according to your needs in the following link: https://pypi.org/
- Installing a specific version of a package:
We may sometimes need to install a specific version of a particular package to suit all our needs. Thus we have a command particularly for this operation as follows:
pip install "Somepkg==1.4"
- To install a version greater than or equal to one version and less than another:
pip install "SomePkg>=1,<2"
- Remove a package:
Removing packages is as easy as installing them using pip. UNINSTALL command is used.
We can uninstall any installed package using the uninstall command below, as we can observe we had previously installed the ‘camelcase’ package using pip. Now let’s remove the same package using the Uninstall command.
pip uninstall camelcase
Uninstalling camelcase-0.2: Would remove: c:\programdata\anaconda3\lib\site-packages\camelcase-0.2.dist-info\* c:\programdata\anaconda3\lib\site-packages\camelcase\* Proceed (y/n)? y Successfully uninstalled camelcase-0.2
- Listing the packages present on the system:
C:\Users\Tirthesh Pawar>pip list
This command lists all the existing packages on your system. Package Version ---------------------------------- --------- alabaster 0.7.12 altair 3.2.0 anaconda-client 1.7.2 anaconda-navigator 1.9.7 anaconda-project 0.8.2
So, friends, these were a few operations you can perform using pip in Python. Thus, Pip is very useful in managing packages in pPython. I hope this post cleared some basic concepts about ‘pip‘. Keep coding!!