Can't import annotations from __future__

Question:

When running the statement

from __future__ import annotations

I get the following error:

Traceback (most recent call last):
  File "/usr/lib/python3.5/py_compile.py", line 125, in compile
    _optimize=optimize)
  File "<frozen importlib._bootstrap_external>", line 735, in source_to_code
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "./prog.py", line 1
    from __future__ import annotations
    ^
SyntaxError: future feature annotations is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.5/py_compile.py", line 129, in compile
    raise py_exc
py_compile.PyCompileError:   File "./prog.py", line 1
    from __future__ import annotations
                                     ^
SyntaxError: future feature annotations is not defined

What could be the cause of this error?

Asked By: Shouko Nishimiya

||

Answers:

Looking at your error traceback, it looks like you are using python 3.5. Is that the case?

If so, then the error happens because according to PEP-563 the import of __future__ annotations is available starting with Python 3.7.

I did not find any hints that this will be backported to previous versions, but I might have missed that.

Answered By: Ralf

it works for me.

pip3 install 'pillow<9'
Answered By: Gavin Gao
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.