Set up Visual Studio code to run Python in bash on Windows

I want to run a python .py file in Visual Studio Code using the Windows bash console.

What I tried to do:

Change the default shell in settings.json :

 { "terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe" } 

Add task to tasks.json to run python command with file name as argument:

 { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "0.1.0", "command": "python", "isShellCommand": true, "showOutput": "always", "tasks": [ { "taskName": "Run python in bash", "suppressTaskName": true, "args": ["${file}"] } ] } 

There are several issues here:

  • Tasks are not executed in bash as I wanted
  • To open a C drive I need to replace C:\ with /mnt/c in the file path

Can you share your solutions with these problems?

+5
source share
1 answer

I don't have Windows 10 with bash , but I think the problem is that you are not really trying to start Python. You are trying to run bash (and then run python ). Try installing the bash command with the parameters ["python", "$file"] .

0
source

Source: https://habr.com/ru/post/1257407/


All Articles