Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"from __future__ import annotations" results in "annotations is not defined" in VSCode

    from __future__ import annotations
SyntaxError: future feature annotations is not defined

I get this error when I try to run my code in the VSCode terminal. I never have this error when I ran my code with PyCharm. I just don't understand what is making it not work in VSCode.

I'm using Python 3.7 as my project interpreter.

like image 343
Bemjamin Zhuo Avatar asked Oct 16 '22 06:10

Bemjamin Zhuo


1 Answers

Unless you created a virtual environment and selected that as your interpreter, typing something like python3 myfile.py will not guarantee you are using the Python interpreter you selected in VS Code (that's under the control of your shell, not VS Code). Make sure to use Run Python File in Terminal as that will make sure your file is run using the selected Python interpreter.

like image 92
Brett Cannon Avatar answered Oct 20 '22 10:10

Brett Cannon