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 importlib_metadata and other requirements when run as `--no-dev`

See original GitHub issue
  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Issue

I’m using poetry inside a docker with poetry config virtualenvs.create false. Poetry requirements are listed in my poetry.lock as dev (they probably are dependencies of some other package). When I run poetry install --no-dev the first time, the command runs fine but poetry removes its own requirements!

...
  - Removing attrs (19.3.0)
  - Removing cffi (1.14.0)
  - Removing cryptography (2.8)
  - Removing idna (2.8)
  - Removing importlib-metadata (1.5.0)
  - Removing jsonschema (3.2.0)
  - Removing pycparser (2.19)
  - Removing pyparsing (2.4.6)
  - Removing pyrsistent (0.15.7)
  - Removing zipp (3.0.0)

The second time poetry is run, I get:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/poetry/utils/_compat.py", line 15, in <module>
    from importlib import metadata
ImportError: cannot import name 'metadata'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/poetry", line 5, in <module>
    from poetry.console import main
  File "/usr/local/lib/python3.6/site-packages/poetry/console/__init__.py", line 1, in <module>
    from .application import Application
  File "/usr/local/lib/python3.6/site-packages/poetry/console/application.py", line 5, in <module>
    from .commands.about import AboutCommand
  File "/usr/local/lib/python3.6/site-packages/poetry/console/commands/__init__.py", line 2, in <module>
    from .add import AddCommand
  File "/usr/local/lib/python3.6/site-packages/poetry/console/commands/add.py", line 5, in <module>
    from .init import InitCommand
  File "/usr/local/lib/python3.6/site-packages/poetry/console/commands/init.py", line 16, in <module>
    from poetry.utils._compat import OrderedDict
  File "/usr/local/lib/python3.6/site-packages/poetry/utils/_compat.py", line 18, in <module>
    import importlib_metadata as metadata
ModuleNotFoundError: No module named 'importlib_metadata'

Issue Analytics

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

github_iconTop GitHub Comments

7reactions
matthijskooijmancommented, Jun 5, 2020

One extra observation: It seems that poetry only removes packages that are mentioned in its pyproject.toml and/or poetry.lock (maybe just one, haven’t checked).

I tried installing an extra package (mysqlclient) using pip directly, then ran poetry install --no-dev and it would again remove importlib-metadata and some others (all of which are listed as (indirect) dev-dependencies), but it would not remove mysqlclient, presumably since it was not listed at all.

A workaround that seems to work, is to add poetry itself as an optional dependency:

poetry add --optional poetry

This adds a ton of extra packages to poetry.lock (all dependencies of poetry), but does not install them on poetry install. Also, it prevents removing them on poetry install --no-dev.

5reactions
finswimmercommented, Oct 11, 2020

Hello,

the problem here is, that poetry and the package are installed in the same environment. One should never mix the installation method within one environment. Either use poetry or pip. But not both at the same time. Because they don’t know each other and break things when a package gets installed or removed by one or another.

When using virtualenvs.create false make sure poetry is installed with the installer script or as an alternative by pipx.

fin swimmer

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why poetry removes some entries after running 'add'?
I'm getting this dependency added to the project, however some other dependencies are automatically removed, namely: importlib-metadata ...
Read more >
Commands | Documentation | Poetry - Python dependency ...
The cache clear command removes packages from a cached repository. For example, to clear the whole cache of packages from the pypi repository,...
Read more >
FoundriesFactory Release 87 (v. 1648) - Foundries.io
Read the release notes and product updates for FoundriesFactory release 87 from Foundries.io. Or browse past notes in the archives.
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