Home > database >  What is the true equivalent of package.json for pip?
What is the true equivalent of package.json for pip?

Time:07-10

I know about requirements.txt, but that only includes a list of dependencies. But what about the other meta information like the package name, author, main function etc. ?

Also i know about setup.py but since i want to programmatically access values inside, i need a configuaration file standard like yaml/json and not python code.

Did the python community come out with something truly comparable to package.json ?

CodePudding user response:

Like the comments on my question answered, it's pyproject.toml together with the poetry package management tool

CodePudding user response:

1. Without 3rd Party Packages

pip freeze > requirements.txt

In the local machine. And in the server,

pip install -r requirements.txt

This installs all the dependencies

2. With a 3rd Party Package

  • pipenv

    I would use pipenv instead of pip. pipenv automatically generate Pipfile and Pipfile.lock that is far superior to requirements.txt

    Install pipenv and setting it for your project

    pip install --user pipenv
    cd yourproject
    pipenv install package1 package2 ...
    

    to install packages from Pipfile is as simple as pipenv install Read more: https://pipenv.pypa.io/en/latest/

  • poetry I have recently moved from pipenv to poetry because poetry has everything pipenv offers and much more. It is end-to-end, as it includes building and publishing of your project to pypi.

    installing poetry

    curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
    

    and set .poetry/bin in your path.

    poetry new yourproject
    cd yourproject
    poetry add packagename
    

    Like pipenv this generate pyproject.toml file that context all your requirements. Like Pipenv, to install your depence

    poetry install
    

    See more: https://poetry.eustace.io/docs/

    See Python packaging war: Pipenv vs. Poetry for short review of these awesome packages

  • Related