Using play button after running selection in terminal use DOS syntax at Python ">>>"
See original GitHub issueVisual Studio Code Python Extension Play button seems to be using DOS syntax on Python command prompt “>>>”. Does not matter which command line is select in terminal (Python or Cmd)
=== I can highlight lines and run Python code (from command pallet “Python: Run Selection/Line in Python Terminal”).
=== But, when I try pressing the PLAY BUTTON I get message (note triple python prompt, but DOS/cmd syntax)
“>>> C:/Users/JimCa/AppData/Local/Programs/Python/Python38/python.exe c:/Users/JimCa/Documents/campaign/CampaignFinance/hello.py
File “<stdin>”, line 1
C:/Users/JimCa/AppData/Local/Programs/Python/Python38/python.exe c:/Users/JimCa/Documents/campaign/CampaignFinance/hello.py
^
SyntaxError: invalid syntax”
=== The paths are correct (even though AppData is hidden)
=== “Run without debugging” from the Run menu works
=== From Help About:
Version: 1.44.2 (system setup) Commit: ff915844119ce9485abfe8aa9076ec76b5300ddd Date: 2020-04-16T16:36:23.138Z Electron: 7.1.11 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Windows_NT x64 10.0.18363
Environment data
- VS Code version: 1.44.2
- Extension version (available under the Extensions sidebar): 2020.4.74986
- OS and version: Windows_NT x64 10.0.18363
- Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.2 (from Python.org)
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
- Relevant/affected Python packages and their versions: XXX
- Relevant/affected Python-related VS Code extensions and their versions: XXX
- Jedi or Language Server? (i.e. what is
"python.jediEnabled"
set to; more info #3977): XXX - Value of the
python.languageServer
setting: XXX
Expected behaviour
Run hello.py
Actual behaviour
“>>> C:/Users/JimCa/AppData/Local/Programs/Python/Python38/python.exe c:/Users/JimCa/Documents/campaign/CampaignFinance/hello.py
File “<stdin>”, line 1
C:/Users/JimCa/AppData/Local/Programs/Python/Python38/python.exe c:/Users/JimCa/Documents/campaign/CampaignFinance/hello.py
^
SyntaxError: invalid syntax”
Steps to reproduce:
[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]
- create hello.py
- file save
- highlight code and select “Python: Run Selection/Line in Python Terminal” from command palette – codes runs OK
- Notice setting of terminal (is it “Cmd” or “Python” either setting will cause error;; if it is set to “CMD” it will flip to “Python” after pressing PLAY button)
- Press the triangular PLAY button
- Will receive syntax error message with text that shows CMD/DOS syntax on a Python “>>>” prompt. The CMD/DOS syntax has the correct file paths, but does not belong at a Python “>>>” prompt
Logs
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
) NONE
XXX
Output from Console
under the Developer Tools
panel (toggle Developer Tools on under Help
; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging
)
XXX
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top GitHub Comments
As long as I know, the “play button” (Run Python File in Terminal), in this extension, runs the command
python file
in the integrated terminal. The line below, that you posted, shows that:If you run this command inside a Python REPL, it will give you that error.
And I also experienced that the the “play button” will create a terminal named “Python” before run the above command. If this terminal already exists, it will be used.
So, if you have a terminal named “Python” running CMD, the above command will be ok. If you have a terminal named “Python” running python REPL, the above command will give you an error.
I have a vague recollection that in my case Python not running was related to my closing a PowerShell session. Apparently, VS Code runs Python in PowerShell and not the Windows/DOS CLI? Making sure I still had PowerShell running seemed to solve the problem.
On Mon, Dec 19, 2022, 7:59 AM Kartik Raj @.***> wrote: