Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip gives an AttributeError: module 'typing' has no attribute '_ClassVar'

Tags:

python-3.x

pip

I'm having trouble with pip on my Windows 10 system. If I try to do anything with pip (such as "pip -h") I get the following:

D:\Downloads\pip\pip-22.0.4>pip -h
Traceback (most recent call last):
  File "C:\Program Files\Python310\Scripts\pip-script.py", line 33, in <module>
    sys.exit(load_entry_point('pip==22.0.4', 'console_scripts', 'pip')())
  File "C:\Program Files\Python310\Scripts\pip-script.py", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "C:\Program Files\Python310\lib\importlib\metadata\__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "C:\Program Files\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python39\Lib\site-packages\pip\_internal\cli\main.py", line 9, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python39\Lib\site-packages\pip\_internal\cli\autocompletion.py", line 10, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python39\Lib\site-packages\pip\_internal\cli\main_parser.py", line 8, in <module>
    from pip._internal.cli import cmdoptions
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python39\Lib\site-packages\pip\_internal\cli\cmdoptions.py", line 23, in <module>
    from pip._internal.cli.parser import ConfigOptionParser
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python39\Lib\site-packages\pip\_internal\cli\parser.py", line 12, in <module>
    from pip._internal.configuration import Configuration, ConfigurationError
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python39\Lib\site-packages\pip\_internal\configuration.py", line 20, in <module>
    from pip._internal.exceptions import (
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python39\Lib\site-packages\pip\_internal\exceptions.py", line 14, in <module>
    from pip._vendor.rich.console import Console, ConsoleOptions, RenderResult
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python39\Lib\site-packages\pip\_vendor\rich\console.py", line 55, in <module>
    from .pretty import Pretty, is_expandable
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python39\Lib\site-packages\pip\_vendor\rich\pretty.py", line 366, in <module>
    class Node:
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python36\Lib\site-packages\dataclasses.py", line 958, in dataclass
    return wrap(_cls)
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python36\Lib\site-packages\dataclasses.py", line 950, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python36\Lib\site-packages\dataclasses.py", line 800, in _process_class
    cls_fields = [_get_field(cls, name, type)
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python36\Lib\site-packages\dataclasses.py", line 800, in <listcomp>
    cls_fields = [_get_field(cls, name, type)
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python36\Lib\site-packages\dataclasses.py", line 659, in _get_field
    if (_is_classvar(a_type, typing)
  File "C:\Users\jxcla\AppData\Local\Programs\Python\Python36\Lib\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'?

I'm not sure when this started happening and I've tried reinstalling pip in numerous ways, but no luck. Same error. I've searched for answers on the web, but nothing has fixed it for me.

I'm a bit of a noob when it comes to this, so it's entirely possible I've done something to gum up the works. Any help would be greatly appreciated.

John

like image 812
jxclark13 Avatar asked Dec 29 '25 16:12

jxclark13


1 Answers

This issue seems to be cropping up for me in a couple of my CI builds. One possible fix seems to be:

pip uninstall dataclasses -y

In my case, I don't know how dataclasses is getting installed (it's supposed to be a built-in not a dependency), but it failed last night when I unpinned the dependency scs.

like image 192
amos Avatar answered Jan 04 '26 12:01

amos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!