Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Python 3.10, but Pylance still says "Alternative syntax for unions requires Python 3.10 or newer"

I just upgraded Python to 3.10 for the new features, and when I do import sys; sys.version using the IPython console in VS Code, it prints Python version 3.10.0. But when I open an editor window and try to enter a type annotation using | for sum types, e.g. x:int|float, Pylance highlights the | and says "Alternative syntax for unions requires Python 3.10 or newer."

Any thoughts?

like image 245
user49404 Avatar asked Oct 17 '25 11:10

user49404


2 Answers

VS Code may be using a different version of python. Make sure that the default python interpreter (under settings, search for python) is python3.10 (if you are using linux, /usr/bin/python3.10 will probably work)

like image 177
William Avatar answered Oct 20 '25 01:10

William


For me the solution was to use "python3" in "Default Interpreter Path". In my case, I noticed that terminal didn't recognize the command "python", but there was "python3" command, which comes with Python v3 and up. So I changed the path to that and I didn't get any errors anymore.

Python Default Interpreter Path

like image 20
f.bele Avatar answered Oct 20 '25 01:10

f.bele



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!