8

I have a Python project that doesn't contain requirements.txt. But it has a pyproject.toml file.

How can I download packages (dependencies) required by this Python project and declared in pyproject.toml using the Pip package manager (instead of the build tool Poetry).

So instead of pip download -r requirements.txt, something like pip download -r pyproject.toml.

john-hen
  • 3,720
  • 2
  • 19
  • 38
Sherein
  • 547
  • 7
  • 19
  • https://stackoverflow.com/questions/35064426/when-would-the-e-editable-option-be-useful-with-pip-install – Andrew Feb 19 '22 at 01:59

3 Answers3

4

pip supports installing pyproject.toml dependencies natively.

As of version 10.0, pip supports projects declaring dependencies that are required at install time using a pyproject.toml file, in the form described in PEP 518. When building a project, pip will install the required dependencies locally, and make them available to the build process. Furthermore, from version 19.0 onwards, pip supports projects specifying the build backend they use in pyproject.toml, in the form described in PEP 517.

From the project's root, use pip's local project install:

python -m pip install .
  • 4
    That command doesn't just download the dependencies, it *installs* them, as well as the actual project itself. – john-hen Nov 15 '21 at 18:32
3

You can export the dependencies to a requirements.txt and use pip download afterwards:

poetry export -f requirements.txt > requirements.txt
pip download -r  requirements.txt
finswimmer
  • 5,331
  • 1
  • 17
  • 28
2

Here is an example of .toml file:

[build-system]
requires = [
    "flit_core >=3.2,<4",
]
build-backend = "flit_core.buildapi"

[project]
name = "aedttest"
authors = [
    {name = "Maksim Beliaev", email = "beliaev.m.s@gmail.com"},
    {name = "Bo Yang", email = "boy@kth.se"},
]
readme = "README.md"
requires-python = ">=3.7"
classifiers = ["License :: OSI Approved :: MIT License"]
dynamic = ["version", "description"]

dependencies = [
    "pyaedt==0.4.7",
    "Django==3.2.8",
]

[project.optional-dependencies]
test = [
    "black==21.9b0",
    "pre-commit==2.15.0",
    "mypy==0.910",
    "pytest==6.2.5",
    "pytest-cov==3.0.0",
]

deploy = [
    "flit==3.4.0",
]

to install core dependencies you run:

pip install .

if you need test(develop) environment (we use test because it is a name defined in .toml file, you can use any):

pip install .[test]

To install from Wheel:

pip install C:\git\aedt-testing\dist\aedttest-0.0.1-py3-none-any.whl[test]
Beliaev Maksim
  • 545
  • 5
  • 15
  • 3
    `pip install .` doesn't just download the dependencies, it *installs* them, as well as the actual project itself. – john-hen Nov 15 '21 at 18:33
  • 1
    true, but maybe this answer will be anyway helpful for somebody. I find limited info on pyproject.toml file – Beliaev Maksim Feb 07 '22 at 09:35