question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using play button after running selection in terminal use DOS syntax at Python ">>>"

See original GitHub issue

Visual 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]

  1. create hello.py
  2. file save
  3. highlight code and select “Python: Run Selection/Line in Python Terminal” from command palette – codes runs OK
  4. 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)
  5. Press the triangular PLAY button
  6. 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 (ViewOutput, 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:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
Diogo-Rossicommented, Apr 28, 2020

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:

>>> C:/Users/JimCa/.../Python38/python.exe   c:/Users/JimCa/Documents/.../hello.py
    ↑______________ python _______________↑   ↑______________ file _______________↑

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.

0reactions
JimCallahanOrlandocommented, Dec 19, 2022

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:

Closing as dup of #2997 https://github.com/microsoft/vscode-python/issues/2997.

— Reply to this email directly, view it on GitHub https://github.com/microsoft/vscode-python/issues/11435#issuecomment-1357626902, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7QNKQW6HOP35ADMGBIFUDWOBLZ7ANCNFSM4MSCYL7Q . You are receiving this because you authored the thread.Message ID: @.***>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running python code using 'Run selection in Python terminal'
Want to see what some Python code will do when run ? Use the ' Run selection in Python terminal ' command from...
Read more >
Python System Command - os.system(), subprocess.call()
We will use Python subprocess module to execute system commands. We can run shell commands by using subprocess.call() function.
Read more >
How to Run Your Python Scripts
This step-by-step tutorial will guide you through a series of ways to run Python scripts, depending on your environment, platform, needs, and skills...
Read more >
Python on Windows FAQ — Python 3.11.1 documentation
Contents: Python on Windows FAQ- How do I run a Python program under ... If you are already familiar with running programs from...
Read more >
How to keep a Python script output window open?
You have a few options: Run the program from an already-open terminal. Open a command prompt and type: python myscript.py.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found