简体   繁体   中英

Download dependencies declared in pyproject.toml using Pip

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 .

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

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 .

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM