I have installed visual studio code and code runner extension. I then have this piece of code:
text: str = "slkdfjsd"
I click CTRL-ALT-N and I get:
text: str = "slkdfjsd"
^
SyntaxError: invalid syntax
I like using types, and this program worked, it looks like its complaining about the types how can I have it understand that types are ok?
more details:
$ /usr/bin/env python3 --version
Python 3.6.6 :: Anaconda, Inc.
and when it's running it with:
[Running] /usr/bin/env python3 "/home/myuser/dev/projects/python-snippets/text-summarization"
File "/home/myuser/dev/projects/python-snippets/text-summarization", line 44
text: str = "slkdfjsd"
^
SyntaxError: invalid syntax
Code runner plugin docs says:
$pythonPath: The path of Python interpreter (set byPython: Select Interpreter command)
but when I run print the path as comments suggested, I get a different version:
sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)
which is different as you can see above from the >python: select interpreter which I have chosen.
Note also that when I run this code in visual studio code with run in terminal instead of CTRL-ALT-N then the python version chosen is 3.6 and it runs fine without any syntax error, so it I think it's something with the code runner not seeing the same python version that I see when selecting >python: select interpreter
Update: I see indeed that code-runner is using the wrong python interpreter as stated above, so I opened my user settings and tried to update python to point to the correct interpreter however it did not change anything it's still using the same wrong interpreter here is what I tried:
{
"git.autofetch": true,
"terminal.integrated.rendererType": "dom",
"code-runner.executorMap": {
"javascript": "node",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"php": "php",
"python": "/home/user/home/user/dev/anaconda3/envs/pymachine/bin/python",
"perl": "perl",
"perl6": "perl6",
"ruby": "ruby",
"go": "go run",
"lua": "lua",
"groovy": "groovy",
"powershell": "powershell -ExecutionPolicy ByPass -File",
"bat": "cmd /c",
"shellscript": "bash",
"fsharp": "fsi",
"csharp": "scriptcs",
"vbscript": "cscript //Nologo",
"typescript": "ts-node",
"coffeescript": "coffee",
"scala": "scala",
"swift": "swift",
"julia": "julia",
"crystal": "crystal",
"ocaml": "ocaml",
"r": "Rscript",
"applescript": "osascript",
"clojure": "lein exec",
"haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
"rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
"racket": "racket",
"ahk": "autohotkey",
"autoit": "autoit3",
"dart": "dart",
"pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
"d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
"haskell": "runhaskell",
"nim": "nim compile --verbosity:0 --hints:off --run"
}
}
However also after changing that (maybe i'm doig something wrong i'm vscode newbie) I still see that the code-runner is running it with:
[Running] /usr/bin/env python3 "/home/myuser/dev/projects/python-snippets/text-summarization"
/usr/bin/env python3as mentioned and the version of it is: ` 3.6.6` as mentioned in the quesion.sys.version_info?ctrl-shift-pand then>python: select interperterlooks like thecode runnerplugin takes it from a different place :(