Search This Blog

Monday, 29 November 2021

Python PIP Package Manager

Python Package Manager (pip):

pip is a package-management system written in Python used to install and manage software packages. It connects to an online repository of public packages, called the Python Package Index. ... Python 2.7. 9 and later (on the python2 series), and Python 3.4 and later include pip (pip3 for Python 3) by default.

Command-line interface

An output of pip install virtualenv

One major advantage of pip is the ease of its command-line interface, which makes installing Python software packages as easy as issuing a command:

pip install some-package-name

Users can also easily remove the package:

pip uninstall some-package-name

Most importantly, pip has a feature to manage full lists of packages and corresponding version numbers, possible through a "requirements" file. This permits the efficient re-creation of an entire group of packages in a separate environment (e.g. another computer) or virtual environment. This can be achieved with a properly formatted file and the following command, where requirements.txt is the name of the file:

pip install -r requirements.txt

To install some package for a specific python version, pip provides the following command, where ${version} is replaced by 2, 3, 3.4, etc.:

pip${version} install some-package-name

Using setup.py

Pip provides a way to install user-defined projects locally with the use of setup.py file. This method requires the python project to have the following file structure:

example_project/
├── exampleproject/      Python package with source code.
|    ├── __init__.py     Make the folder a package.
|    └── example.py      Example module.
└── README.md            README with info of the project.

Within this structure, user can add setup.py to the root of the project (i.e. example_project for above structure) with the following content:

from setuptools import setup, find_packages

setup(
    name='example',  # Name of the package. This will be used, when the project is imported as a package.
    version='0.1.0',
    packages=find_packages(include=['exampleproject', 'exampleproject.*'])  # Pip will automatically install the dependences provided here.
)

After this, pip can install this custom project by running the following command, from the project root directory:

pip install -e .


No comments:

Post a Comment

how to implement YOLOv3 using Python and TensorFlow

Object Detection with YOLOv3 Introduction YOLOv3 (You Only Look Once version 3) is a real-time object detection algorithm that can detect ob...