Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
843 views
in Technique[技术] by (71.8m points)

visual studio code - Ampersand "&" syntax error running any Python script in VSCode?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...