Search code examples
pythondependenciespython-poetry

The difference between `poetry add` and `poetry install`


I've thought that poetry add package would simply add the package to pyproject.toml but it seems it doesn't just add but also installs it in a virtual environment.

But what does poetry install do? When I run it after I added the deps with add, I am getting the following message:

Installing dependencies from lock file

No dependencies to install or update

Note that I started a project from scratch with mkdir new_dir; cd new_dir; poetry init.


Solution

  • poetry add library_name installs the library and adds it to the pyproject.toml file. Note - both installs the library and adds it to the file.

    poetry install is used when you've directly edited the pyproject.toml file and added the dependency names manually. In that case, they aren't installed yet, so, poetry install takes care of that.