Skip to content

Dependencies with Different Import Names Incorrectly Reported as Unused #1089

@ViaDav1d

Description

@ViaDav1d

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! 🚀

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwaiting for answerWaiting from answer from the reporter

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions