question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Poetry removes it's own dependencies with `install --no-dev` when it manages the environment it is installed in

See original GitHub issue

Issue

When you specify a package in the dev-dependencies that is either a dependency of the poetry itself or it depends on one of the poetry dependencies, and you’ve installed poetry inside an environment that poetry is supposed to manage, poetry will uninstall this mentioned dependency after invoking poetry install --no-dev, making itself unusable in the future.

I’m aware that it is advised to install poetry outside of the environment it should manage, but this is very often seen inside docker images (such example provided in the gist linked above) to save on the resources.

Example output presenting mentioned issue (without -vvv ands):

$ pip install poetry
Requirement already satisfied: pip in /usr/local/lib/python3.9/site-packages (21.0.1)
Collecting poetry
  Downloading poetry-1.1.6-py2.py3-none-any.whl (172 kB)
[ ... 70 irrelevant output lines truncated ... ]
Collecting appdirs<2,>=1.4.3
  Downloading appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB)
Installing collected packages: [ ... ] appdirs, [ ... ] poetry
Successfully installed [ ... ] appdirs-1.4.4 [ ... ] poetry-1.1.6 [ ... ]

$ poetry config virtualenvs.create false && poetry install --no-dev

Skipping virtualenv creation, as specified in config file.
Installing dependencies from lock file

Package operations: 0 installs, 0 updates, 1 removal

  • Removing appdirs (1.4.4)
Removing intermediate container af920367a74d

As you can see, appdirs, which is required by the poetry, was uninstalled by poetry. Full log, with the -vvv and the attempt to run poetry again, available here

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:18
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
gbdlincommented, Apr 17, 2021

If this is expected, it’s for sure not documented properly. Both in the documentation and when just using poetry install --help, the --no-dev option is described as Do not install the development dependencies., not Get rid of the development dependencies. There is also a 2nd command line options --remove-untracked, from which I would expect to remove some dependencies.

But even if the --no-dev’s expected behavior is to remove all dev dependencies, poetry should do one of those:

  • do an exception for its own dependencies if it’s being run from the same virtualenv,
  • don’t remove anything implicitly when it’s being run from the same virtualenv,
  • provide additional command line option that allows skipping the removal of dev dependencies.
0reactions
finswimmercommented, Mar 24, 2022

This has change with poetry 1.2.0a2: Poetry wan’t remove installed packages unless the --sync option is given.

However, if a dependency will be removed due to a version change e.g. on poetry update the package will be removed of course from the venv.

fin swimmer

Read more comments on GitHub >

github_iconTop Results From Across the Web

Commands | Documentation | Poetry - Python dependency ...
poetry install Installing dependencies from lock file No dependencies to install or update - Installing <your-package-name> (x.x.x).
Read more >
Dependency Management With Python Poetry
Work With Python Poetry. Use Poetry's Virtual Environment; Declare Your Dependencies; Install a Package With Poetry. Handle poetry.lock.
Read more >
How To Install Poetry to Manage Python Dependencies on ...
In this tutorial you will install Poetry using the official installation script, set up a Poetry project with a virtual environment, then add...
Read more >
Configure a Poetry environment | PyCharm Documentation
You can declare the libraries your project depends on, and Poetry will install and update them for you. Project dependencies are recorded in...
Read more >
why poetry removes virtualenv? - Stack Overflow
You are mixing two different installation concepts and the second overrides the first. ... Thus, poetry is overriding it's own dependencies.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found