deptry icon indicating copy to clipboard operation
deptry copied to clipboard

Dependencies with Different Import Names Incorrectly Reported as Unused

Open ViaDav1d opened this issue 8 months ago • 3 comments

I'm experiencing a false positive with deptry, where scikit-learn is marked as an unused dependency despite being used in my project. This appears to be due to module aliasing, where the installed package (scikit-learn) has a different import name (sklearn).

I noticed that PR #1033 aimed to fix issues related to transitive dependencies with different module names, but this issue still persists in the latest version of deptry.

Steps to Reproduce

  1. Install scikit-learn: pip install scikit-learn

  2. Create a simple Python script (example.py): from sklearn.model_selection import train_test_split

  3. Run deptry in the project directory: deptry --verbose

  4. Observe that scikit-learn is incorrectly flagged as an unused dependency (DEP002). Expected Behavior - eptry should recognize that scikit-learn is in use and not mark it as an unused dependency.

Actual Behavior deptry incorrectly reports:

Unused dependencies found: scikit-learn

Environment deptry version: 0.23.0 Python version: 3.13.2

Additional Information This issue might be related to how deptry detects dependencies when the installed package name differs from the imported module name.

Other libraries with similar aliasing may also be affected.

Can this be investigated further to properly handle cases where the installed package name differs from the import name? If there's a known workaround, I'd love to hear about it.

Thanks for the great work on deptry! 🚀

ViaDav1d avatar Mar 12 '25 13:03 ViaDav1d