[Python] Python ModuleNotFoundError: No module named 'PyQt6.QtChart' despite pip install and...

Discussão em 'Python' iniciado por Stack, Junho 25, 2025.

  1. Stack

    Stack Membro Participativo

    Problem Summary: Persistent ModuleNotFoundError for PyQt6.QtChart on Windows

    I'm repeatedly encountering a ModuleNotFoundError: No module named 'PyQt6.QtChart' error when launching my PyQt6 application on Windows 10/11. The error occurs specifically at the line from PyQt6.QtChart import ... in my ui.py file.

    Key observations and troubleshooting performed:

    Error Consistency: The error is consistently ModuleNotFoundError for PyQt6.QtChart.

    Installation Confirmed: When I run pip install PyQt6-Charts (or pip list) targeting the exact Python executable used to run the script (e.g., "C:\Users\clemc\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\python.exe"), pip unequivocally states Requirement already satisfied: PyQt6-Charts (6.7.0). This strongly suggests the package is installed for that specific Python interpreter.

    Code Integrity: The ui.py file has been fully reviewed and corrected for import order and other TypeError issues (e.g., QMessageBox argument types). The import statement itself is syntactically correct.

    Environment Attempts: I've tried running from both PowerShell and Command Prompt, and explicitly used the full path to python.exe to launch main.py. pycache has been cleared multiple times.

    Python Source: The Python installation is from the Microsoft Store, which is often cited as a source of environment pathing and module discovery issues on Windows.

    The core paradox: The module is confirmed as installed by pip for the specific Python executable, yet Python fails to find it when executing the script. This points towards a very stubborn environment or pathing issue, likely exasperated by the nature of Microsoft Store Python installations.

    Nothing work

    I need some helps to fix this, Gemini helps me to create this.

    Okay, here's a quick summary in English of what we've done so far to troubleshoot the ModuleNotFoundError:

    Quick Summary of Troubleshooting Steps:

    We've been battling a persistent ModuleNotFoundError: No module named 'PyQt6.QtChart' when running a PyQt6 application on Windows.

    Here's what we've tried:

    Code Review & Fixes:

    Verified and corrected the order of PyQt6 imports in ui.py (ensuring QtWidgets comes before QtChart).

    Fixed TypeError issues related to QMessageBox argument passing (missing self parent).

    Replaced the ui.py content with a full, corrected version to eliminate any hidden code problems.

    Package Installation Verification:

    Repeatedly ran pip install PyQt6 PyQt6-Charts matplotlib numpy.

    Confirmed PyQt6-Charts is listed by pip list as 6.7.0.

    Crucially, explicitly targeted the exact Python executable path (e.g., C:\Users\clemc\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\python.exe) for pip install and pip list, which returned Requirement already satisfied. This indicates the package is installed for the Python interpreter attempting to use it.

    Environment Management:

    Tried running from both PowerShell and Command Prompt (CMD) to rule out shell-specific syntax issues.

    Used the full, explicit path to python.exe to launch main.py (e.g., "C:\Users...\python.exe" main.py) to ensure the correct interpreter is used.

    Regularly cleared pycache directories.

    Discussed and attempted to set up a dedicated virtual environment.

    The Paradox: Despite pip clearly showing PyQt6.QtChart as installed for the active Python executable, the ModuleNotFoundError persists. This strongly suggests a deep-seated environmental conflict or module discovery issue, likely exacerbated by the Python installation being from the Microsoft Store on Windows.

    Continue reading...

Compartilhe esta Página