[Python] Typing / Dataclasses Conflict in Python 3.12: "AttributeError: module 'typing' has no...

Discussão em 'Python' iniciado por Stack, Julho 22, 2025.

  1. Stack

    Stack Membro Participativo

    I'm encountering a persistent and environment-breaking issue while trying to install .whl packages offline in Python 3.12. The problem started after running a custom script to install .whl files from a shared folder, and now even basic pip commands fail due to a corrupted or incompatible typing or dataclasses module.

    My Setup

    • Python Version: 3.12 (installed at C:\Program Files\Python312\python.exe)
    • Offline setup: Using pip install --no-index --no-deps on .whl files stored in a local folder
    What I'm Trying to Do


    I created a script that loops over .whl files in a folder and installs them silently using pip like this:

    import os
    import subprocess
    import sys
    import site

    def install_whl_packages(directory):
    whl_files = [f for f in os.listdir(directory) if f.endswith('.whl')]
    for whl in whl_files:
    whl_path = os.path.join(directory, whl)
    subprocess.check_call([sys.executable, "-m", "pip", "install", "--no-index", "--no-deps", whl_path])

    install_whl_packages(r"C:\Users\nguyene\Downloads\7-21 Test")

    Problem


    After installing packages this way (example: absl_py-2.3.1-py3-none-any.whl), my Python environment broke. Every time I run any Python or pip command, I get this fatal error:

    AttributeError: module 'typing' has no attribute '_ClassVar'. Did you mean: 'ClassVar'?


    Full traceback (during pip install):

    File "C:\Users\...\AppData\Roaming\Python\Python312\site-packages\dataclasses.py", line 550, in _is_classvar
    return type(a_type) is typing._ClassVar
    ^^^^^^^^^^^^^^^^
    AttributeError: module 'typing' has no attribute '_ClassVar'. Did you mean: 'ClassVar'?


    Yet when I check typing in Python:

    import typing
    print(typing.__file__)


    It correctly points to the built-in one:

    C:\Program Files\Python312\Lib\typing.py


    However, when I check pip list or attempt another .whl install, it still crashes. I’ve verified that there was a rogue dataclasses.py and dataclasses.cpython-312.pyc under:

    C:\Users\nguyene\AppData\Roaming\Python\Python312\site-packages


    Even after manually deleting those, the issue seems to persist or re-emerge.

    What I’ve Tried

    • Deleted any rogue dataclasses files under AppData\Roaming\...
    • Deleted typing.py and __pycache__ if they appear in user site-packages
    • Restarted VSCode and PowerShell
    • Verified correct typing source path via typing.__file__
    • Ran pip with verbose output — still same error
    • Cleared pip cache
    My Questions

    1. What could be causing this typing._ClassVar error to persist even after removing the rogue dataclasses file?
    2. Could a .whl I installed be re-injecting dataclasses or modifying Python paths silently?
    3. How do I fully reset my user site-packages (without touching system Python)?
    4. Is there a better approach for managing .whl installations offline that prevents this kind of rogue dependency problem?

    Any help or insights would be hugely appreciated — I’ve been trying to fix this for weeks and need to get .whl installation working again without breaking the environment. Happy to share logs or try suggested fixes.

    Thanks in advance!

    Continue reading...

Compartilhe esta Página