Installed packages with a hyphen/underscore are not recognized
xanthics opened this issue · 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
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
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
@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.
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
That should have a prompt to install the module like this
However the scenario of having something in requirements.txt but not installed yet is handled correctly
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 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.
@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.
Still not fixed https://youtrack.jetbrains.com/issue/PY-52795