0

I am trying to install a python package from my organization's Bitbucket instance which I have been developing using the below commands:

$ python -m venv venv
$ source venv/bin/activate
(venv) $ pip install git+https://bitbucket.company.com/path/to/package.git

Even though I was able to install my python package into venv but I was expecting it to install the necessary dependencies which I have specified in requirements.txt also!!!

What all changes I need to make to my python package to install the dependencies also?

Below is my package project structure:

.
├── pyproject.toml
├── README.md
├── requirements.txt
├── src
│   └── package
│       ├── __init__.py
│       └── main.py
└── tests
    └── test_dummy.py

N.b., I am using hatchling for building my python package

sinoroc
  • 18,409
  • 2
  • 39
  • 70
  • 1
    Did you specify in `pyproject.toml` to install requirements.txt? `but I was expecting it` Why were you expecting it? Did you read documentation that it would do that? – KamilCuk Apr 24 '23 at 07:34
  • 1
    For *pip* (and any other installer) to automatically installed the dependencies, these dependencies have to be listed in the project's packaging metadata (not in `requirements.txt`). The way to do it is to write the list of [dependencies in `pyproject.toml`](https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#dependencies-optional-dependencies) (aside: make sure to only list the direct dependencies and use only loose version constraints). – sinoroc Apr 24 '23 at 08:21

1 Answers1

2

For pip (and other installers) to automatically install the dependencies of the project along the project itself, the dependencies have to be listed in the project's packaging metadata (not in requirements.txt). The way to do it is to write the list of dependencies in pyproject.toml

Aside: Make sure to only list the direct dependencies and use only loose version constraints (no pinned dependencies in project packaging metadata, the pinned dependencies belong in requirements.txt only). You can find some discussion about this topic here (it is a bit outdated, but the concept of "abstract vs. concrete dependencies" still holds).

For Hatch (and hatchling) specifically there is documentation about dependencies here, but since this follows a standard specification, you can find it documented in many other places.

sinoroc
  • 18,409
  • 2
  • 39
  • 70