4
votes

In VSCode, I typically run a Python Script using the Python extension and right clicking a .py script and selecting "Run Python File in Terminal". Before today this method worked fine, but now I'm experiencing the below issue...

$ & C:/Users/.../Python/Python37-32/python.exe c:/.../test.py
bash: syntax error near unexpected token `&'

Now I can't run my python scripts using this method. I can see the cause of the error, I'm just not sure why VSCode is prefixing that ampersand, and whether it was doing that before or not.

I was playing around with virtualenv, and perhaps this is the cause, but I'm experiencing this issue even when the virtual environment is not active. I've restarted VSCode and my PC, it appears to be broken.

5
Im not sure that the solution is, but looks like this is the reason it happens github.com/Microsoft/vscode/issues/19839#issuecomment-277574280 - Ron Serruya
@RonSerruya Thanks, that helped. I was able to resolve the issue by downgrading my version of the Python extension to the previous version. It seems like their latest version (released only hours ago) might have this bug. - Dom

5 Answers

2
votes

Instead of downgrading, you can also change the default terminal from cmd to powershell.
To do so, go to your settings.json and replace the "terminal.integrated.shell.windows" parameter
from the path to cmd (e.g. "C:\\Windows\\System32\\cmd.exe")
to the path to powershell (e.g. "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe") If you are using VScode press ctrl+shift+p and search for default terminal and change it to powershell.

1
votes

Fixed this by downgrading my version of the Python extension to the previous version. It appears as though the latest version (released only hours ago) is bugged (for me at least).

1
votes

I am experiencing the same bug with release 2021.5.842923320 (05-14-2021).

Adding "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe" to the settings is a workaround.

Further information can be found in Issue #16175.

0
votes

Confirmed. I have that problem too. Repeating the run command in TERMINAL and manually removing "&" at the beginning of the run command will let the code run.

0
votes

I had the same issue with the additional & character in front of the python command. This bug has been fixed meanwhile with release 2019.5.18678 (5 June 2019) of the Python extension.