question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cannot import name '_Union'

See original GitHub issue
  • cattrs version: 0.9.0
  • Python version: 3.5.2
  • Operating System: ubuntu xenial64

Description

On a clean ubuntu VM, I pip3 install cattrs, and import cattr doesn’t seem to work.

Is something funny with the typing module in python 3.5.2 or something? It looks like travis tested Python 3.5, so I don’t understand how this happened.

What I Did

> vagrant init ubuntu/xenial64
...
> vagrant up
...
> vagrant ssh
...
vagrant@ubuntu-xenial:~$ wget https://bootstrap.pypa.io/get-pip.py
...
vagrant@ubuntu-xenial:~$ sudo python3 get-pip.py
...
vagrant@ubuntu-xenial:~$ pip3 install cattr
...
Successfully installed attrs-18.2.0 cattrs-0.9.0
vagrant@ubuntu-xenial:~$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cattr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/cattr/__init__.py", line 2, in <module>
    from .converters import Converter, UnstructureStrategy
  File "/usr/local/lib/python3.5/dist-packages/cattr/converters.py", line 3, in
<module>
    from ._compat import (
  File "/usr/local/lib/python3.5/dist-packages/cattr/_compat.py", line 86, in <module>
    from typing import _Union
ImportError: cannot import name '_Union'
>>> import typing
>>> dir(typing)
['AbstractSet', 'Any', 'AnyMeta', 'AnyStr', 'AsyncIterable', 'AsyncIterator', 'Awaitable', 'BinaryIO', 'ByteString', 'CT', 'Callable', 'CallableMeta', 'Container', 'DefaultDict', 'Dict', 'Final', 'FrozenSet', 'Generator', 'Generic', 'GenericMeta', 'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator', 'KT', 'KeysView', 'List', 'Mapping', 'MappingView', 'Match', 'MutableMapping', 'MutableSequence', 'MutableSet', 'NamedTuple', 'NewType', 'Optional', 'OptionalMeta', 'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs', 'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt', 'SupportsRound', 'T', 'TYPE_CHECKING', 'T_co', 'T_contra', 'Text', 'TextIO', 'Tuple', 'TupleMeta', 'Type', 'TypeVar', 'TypingMeta', 'Union', 'UnionMeta', 'VT', 'VT_co', 'V_co', 'ValuesView', '_ForwardRef', '_FrozenSetMeta', '_G_base', '_Protocol', '_ProtocolMeta', '_TypeAlias', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_eval_type', '_geqv', '_get_defaults',
'_get_type_vars', '_gorg', '_next_in_mro', '_overload_dummy', '_qualname', '_type_check', '_type_repr', '_type_vars', 'abc', 'abstractmethod', 'abstractproperty', 'cast', 'collections', 'collections_abc', 'contextlib', 'functools', 'get_type_hints', 'io', 'no_type_check', 'no_type_check_decorator', 'overload', 're', 'stdlib_re', 'sys', 'types']

there is no '_Union' in there on my local system, I have python 3.6.4

Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import typing
>>> dir(typing)
['AbstractSet', 'Any', 'AnyStr', 'AsyncContextManager', 'AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable', 'BinaryIO', 'ByteString', 'CT_co', 'Callable', 'CallableMeta', 'ChainMap', 'ClassVar', 'Collection', 'Container', 'ContextManager', 'Coroutine', 'Counter', 'DefaultDict', 'Deque', 'Dict', 'FrozenSet', 'Generator', 'Generic', 'GenericMeta', 'Hashable', 'IO', 'ItemsView', 'Iterable', 'Iterator', 'KT', 'KeysView', 'List', 'Mapping', 'MappingView', 'Match', 'MethodDescriptorType', 'MethodWrapperType', 'MutableMapping', 'MutableSequence', 'MutableSet', 'NamedTuple', 'NamedTupleMeta', 'NewType', 'NoReturn', 'Optional',
'Pattern', 'Reversible', 'Sequence', 'Set', 'Sized', 'SupportsAbs', 'SupportsBytes', 'SupportsComplex', 'SupportsFloat', 'SupportsInt', 'SupportsRound', 'T', 'TYPE_CHECKING', 'T_co', 'T_contra', 'Text', 'TextIO', 'Tuple', 'TupleMeta', 'Type', 'TypeVar', 'TypingMeta', 'Union', 'VT', 'VT_co', 'V_co', 'ValuesView', 'WrapperDescriptorType', '_Any', '_ClassVar', '_FinalTypingBase', '_ForwardRef', '_G_base', '_NoReturn', '_Optional', '_PY36', '_Protocol', '_ProtocolMeta', '_TypeAlias', '_TypingBase', '_TypingEllipsis', '_TypingEmpty', '_Union', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_allowed_types', '_check_generic', '_cleanups', '_collections_abc', '_eval_type', '_generic_new', '_get_defaults', '_get_type_vars', '_make_nmtuple', '_make_subclasshook', '_next_in_mro', '_no_slots_copy', '_overload_dummy', '_prohibited', '_qualname', '_remove_dups_flatten', '_replace_arg', '_special', '_subs_tree', '_tp_cache', '_trim_name', '_type_check', '_type_repr', '_type_vars', 'abc', 'abstractmethod', 'abstractproperty', 'cast', 'collections',
'collections_abc', 'contextlib', 'functools', 'get_type_hints', 'io', 'no_type_check', 'no_type_check_decorator', 'overload', 're', 'stdlib_re', 'sys', 'types']

That one has a '_Union'

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
shreyashagcommented, Mar 16, 2020

This needs to be fixed, can’t run airflow!

1reaction
diefanscommented, Nov 21, 2019

The question is: when it gets released? As of https://github.com/Tinche/cattrs/issues/74 people start to release their forks on pypi already 😦 which indicates, that this project is more used than obvious…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sphinx doesn't support python 3.10 · Issue #9562 - GitHub
ImportError : cannot import name 'Union' from 'types' ... from types import UnionType # type: ignore # python 3.10 or above.
Read more >
cannot import name 'Union' from '_ctypes' (unknown location)
ImportError : cannot import name 'Union' from '_ctypes' (unknown location) · create a virtual environment In a new directory, using python 3.8.
Read more >
257694 – devel/cmake: Fails to build with Python 3.10
Bug 257694 - devel/cmake: Fails to build with Python 3.10: ImportError: cannot import name 'Union' from 'types'.
Read more >
ImportError: cannot import name '_unicodefun' from 'click'
When running our lint checks with the Python Black package, an error comes up: ImportError: cannot import ...
Read more >
[Bug 257694] devel/cmake: Fails to build with Python 3.10
[Bug 257694] devel/cmake: Fails to build with Python 3.10: ImportError: cannot import name 'Union' from 'types'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found