I use the extension code-runner for my VS code to run it directly in the app without a terminal and I had a problem where I had the latest version of Python installed (3.10.0) I had selected that version as my interpreter yet code-runner was running my code in python2.
Here is the solution which worked for me:
As a beginner, I could not understand the way other solutions were explained so I hope this helps:
Go to your User Settings .json by opening the Command Palette with View > Command Palette or by pressing Command+Shift+P on Mac or Ctrl+Shift+P on Windows. Then search for Preferences: Open Settings(JSON)
in a new tab, once again open the command palette but this time look for Preferences: Open User Settings
in the 'Search settings' bar at the top search for 'Shebang'. Make sure that the box of ' Code-runner: Respect Shebang ' is not ticked.
go back to your .json settings file and check that the following line of code is in there: "code-runner.respectShebang": false,
if not, first reload the page, searching for Developer: Reload window in the command palette.
if it still isn't there you will need to add it yourself alongside all your other settings like so:
You will need to go again to Preferences: Open User Settings in the command palette and in the settings search bar look for Code-runner: Executor Map . If it is not in your settings.json file then you will need to press the little settings/gear icon which pops up when you hover your cursor over it and then select ' Copy Setting as JSON '.
Go back to your settings.json file and paste it in there alongside all your other settings like with Shebang. it should look something like this:
My problem was with python (but this applies to any other language). Go to the line "python": "python -u",
and change it to "python": "python3 -u",
.
This solved the issue for me. :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.