requirements icon indicating copy to clipboard operation
requirements copied to clipboard

Installed packages with a hyphen/underscore are not recognized

Open xanthics opened this issue 2 years ago • 6 comments

Describe the bug If you install a package with a hyphen, such as more-itertools, and then import it import more_itertools, you are not given a context action to add it to requirements.txt

Screenshots image

IDE:

  • OS: Win10
  • Product: PyCharm Community
  • Version: 2021.3.1
  • Project SDK: Python 3.10.1

Plugin (please complete the following information. See Main Menu -> File -> Settings -> Plugins):

  • Version 2021.4.1-213-EAP-SNAPSHOT

xanthics avatar Jan 06 '22 12:01 xanthics

@xanthics From the screenshot, it seemed to me that the context action belongs to the attrs package. This inspection and quick fix is not implemented in the Requirements plugin, but in Pycharm itself. As far as I understand, it requires all imported packages to be explicitly listed in requirements.txt. That is, it looks like the correct behavior. But if I misunderstood, then let's try to figure it out

meanmail avatar Jan 30 '22 08:01 meanmail

@xanthics From the screenshot, it seemed to me that the context action belongs to the attrs package. This inspection and quick fix is not implemented in the Requirements plugin, but in Pycharm itself. As far as I understand, it requires all imported packages to be explicitly listed in requirements.txt. That is, it looks like the correct behavior. But if I misunderstood, then let's try to figure it out

The issue in my case and as I understood the issue to be was packages with underscores (such as yt_dlp) were not detected as being installed. However, this appears to have magically been fixed for me today and I'm not sure if it's because of PyCharm's update, an update you released, or a pip update.

DatGuy1 avatar Jan 30 '22 13:01 DatGuy1

Apologies for the confusion with attrs, it was only included to show that the plugin is installed and functioning. To be specific: install more-itertools, import more_itertools, missing the expected context action to add it to requirements.txt

With further testing prompted by DatGuy1's comment, it appears Pycharm itself doesn't properly handle those libraries either. This is after uninstalling more-itertools image That should have a prompt to install the module like this image

However the scenario of having something in requirements.txt but not installed yet is handled correctly image


I've also tried updating to the latest Pycharm Community Release Candidate (2021.3.2) and making sure all plugins and modules are updated

[edit] I created an issue for Pycharm with their context menus as well https://youtrack.jetbrains.com/issue/PY-52795

xanthics avatar Jan 30 '22 14:01 xanthics

@xanthics I had exactly the same issue as in your last screenshot. What's your Python and pip version? I'm on Python 3.10.2, pip 22.0.

DatGuy1 avatar Jan 30 '22 15:01 DatGuy1

@xanthics I had exactly the same issue as in your last screenshot. What's your Python and pip version? I'm on Python 3.10.2, pip 22.0.

Both are with pip 22.0

Python 3.10.1 Pypy 3.8 v7.3.7


After updating Python to 3.10.2, updating pip, and rebuilding the venv behaviour is unchanged.

xanthics avatar Jan 30 '22 17:01 xanthics

Still not fixed https://youtrack.jetbrains.com/issue/PY-52795

meanmail avatar Oct 11 '22 04:10 meanmail