Python - Dependency Management

Card Puncher Data Processing

About

Code Shipping - Dependency (Coupling)

Declaration

See:

requirement specifier

When you install a package, or declaring a dependency, you need to specify an package id that's known in Python as a requirement specifier.

It's the setuptools and pkg_resources package syntax

PyPiProjectName [extra's] [comparison_operator version_identifier]

where:

  • PyPiProjectName is the project’s PyPI name,
  • optionally followed by a comma-separated list of “extras” in square brackets,
  • optionally followed by a comma-separated list of version specifiers where a version specifier is:
    • one of the operators <, >, ⇐, >=, == or !=,
    • followed by a version identifier.

Example of requirement specifiers:

docutils >= 0.3

# comment lines and \ continuations are allowed in requirement strings
BazSpam ==1.1, ==1.2, ==1.3, ==1.4, ==1.5, \
    ==1.6, ==1.7  # and so are line-end comments

# Extra
PEAK[FastCGI, reST]>=0.5a4

setuptools==0.5a7

Non Mandatory (Extras)

https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras

Location

Setup.py

Library dependencies are specified in the install_requires property of the Python - setup.py file.

It takes a string or list of strings containing requirement specifiers specifying what other distributions need to be installed.

When the project is installed by pip, this is the specification that is used to install its dependencies.

Example:

each requirement must begin on a new line.

install_requires=required,
install_requires=['projectname>=0.3']
install_requires=[
   'projectnameA>=1,<2',
   'projectnameB>=2'
]

where:

Operating System

https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-platform-specific-dependencies

Requirement file

Pip Requirements Files

There is no dependency tree mechanism

Example of file:

requests==2.11.1
websocket-client==0.37.0
...

Pipfile

There is no dependency tree mechanism. Use setuppy

Pipfile is the configuration file of the pipenv utility and is aimed to an application. (Weird). Ie a library that will never be reused by others.

Pipfile and its sister Pipfile.lock are a replacement for the existing standard pip's requirements.txt file

See:

Management

Installation

From setup.py file

pip install -e .
pip install -e git+https://somerepo/bar.git#egg=bar

where:

  • The first line says to install your project and any dependencies.
  • The second line overrides the “bar” dependency, such that it’s fulfilled from VCS, not PyPI.

From setup.py file without dependency

Installation without dependency

pip install XXX --no-deps

From a Requirements File

With a Pip Requirements Files in a virtual environment or global

pip install -r requirements.txt

List

  • List the package (dependency) installed in your environment
pip list --format=columns
Package          Version
---------------- -------
Flask            0.11.1
pip              18.1
requests         2.11.1
setuptools       39.0.1
...

Specification

Documentation / Reference





Discover More
Card Puncher Data Processing
Python - EasyInstall

Easy_Install install regular package old tool ? EasyInstall install egg distribution ...
Card Puncher Data Processing
Python - Egg distribution (bdist_egg)

Python Eggs are a python binary distribution format. wheelDoc A “Python egg” is a logical structure embodying the release of a specific version...
Card Puncher Data Processing
Python - Project

Project in Python as describe by The project name is specified in the name properties in the setup function of the setup.py file Project are a set of file to package a package.: one package...
Idea Pipenv Sdk
Python - pipenv (dependency framework)

pip+venv = pipenv pipenv is a dependency framework for Python. See it will install a Example The created Pipfile (configuration)....



Share this page:
Follow us:
Task Runner