Skip to content

Run Python File passes literal quotes in script path to terminal #26274

Description

Description

Behaviour

The top-right Run Python File button fails when the Python script is in a path containing spaces and Python Environments handles terminal execution.

Expected: Python runs the selected file.

Actual: The terminal receives a script argument with literal double quotation marks inside single quotes. Redacted equivalent of the observed command:

/usr/local/bin/python3 '"/path with spaces/main.py"'

Python reports [Errno 2] No such file or directory because the double quotation marks become part of the filename. The error path includes the current directory followed by "/path with spaces/main.py" instead of the actual script path.

Steps to reproduce

  1. Install and enable the Python and Python Environments extensions.
  2. Open a Python file inside a directory with spaces in its path.
  3. Click the top-right Run Python File button.
  4. Observe the terminal command and error.

Running the same script directly with a correctly quoted shell path succeeds.

Diagnostic data

  • VS Code: 1.145.0 (arm64)
  • Python extension: 2026.10.0
  • Python Environments extension: 1.42.0
  • Python interpreter: 3.14.7 at /usr/local/bin/python3
  • OS: macOS
  • Terminal shell: zsh

Issue Details

Item Value
Issue Category Bug
Target Python
Repository Microsoft/vscode-python
VS Code Version Code 1.145.0 (Universal) (a717861c07586a53d83b80d742cd3f59b20a6273, 2026-11-03T15:03:51-08:00)
OS Version Darwin arm64 25.6.0
Extension Identifier ms-python.python
Extension Version 2026.10.0
Extension Publisher ms-python

Activity

  1. akoronn commented on Nov 9, 2026

    @akoronn

    Bug: "Run Python File" passes literal quotation marks in the script path on Windows PowerShell

    Description

    When using the Run Python File command in VS Code, extra double quotation marks are included in the script path passed to Python.

    As a result, Python cannot locate the script and exits with an Invalid argument error.

    This issue started occurring after a recent VS Code update. The same workflow worked correctly before the update.

    Steps to Reproduce

    1. Open a Python project in VS Code.
    2. Use a project directory whose path contains spaces and non-ASCII characters (Japanese characters in my case).
    3. Create and activate a virtual environment.
    4. Open a Python file.
    5. Click Run Python File.

    Actual Behavior

    VS Code generates the following command:

    & '<project-path>\.venv\Scripts\python.exe' '"<project-path>/gui.py"'

    Notice that the script path contains an additional pair of double quotation marks inside the single-quoted PowerShell argument.

    Python interprets these double quotation marks as part of the filename and fails to open the script.

    Error message:

    python.exe: can't open file '<project-path>\"<project-path>\gui.py"': [Errno 22] Invalid argument
    

    Expected Behavior

    The command should pass the script path without the extra literal double quotation marks:

    & '<project-path>\.venv\Scripts\python.exe' '<project-path>/gui.py'

    The script should execute normally.

    Additional Information

    • The issue occurs only when using Run Python File.
    • Running the same script through the VS Code debugger (F5) works correctly.
    • Running the script manually with a correctly quoted command also works.
    • The virtual environment is activated successfully.
    • The project path contains both spaces and Japanese characters.
    • This issue did not occur before a recent VS Code update.

    This suggests that the issue is related to command generation or argument quoting in the Python extension's terminal execution path.

    Environment

    Operating System

    • Windows 11
    • Windows_NT x64 10.0.26300
    • PowerShell

    VS Code

    • Version: 1.145.2 (User Setup)
    • Commit: c4453f8ea430795f941c1b2ff6c9321135a74a02
    • Date: 2026-11-06T04:28:13Z
    • Electron: 43.8.3
    • Chromium: 150.0.7871.250
    • Node.js: 24.22.1
    • V8: 15.0.245.31-electron.0

    Python

    • Version: 3.14.8
    • Interpreter: .venv\Scripts\python.exe

    Extensions

    • Python (ms-python.python): 2026.10.0
    • Python Debugger (ms-python.debugpy): 2026.7.13061010
    • Python Environments (ms-python.vscode-python-envs): 1.43.2026110501
    • Pylance (ms-python.vscode-pylance): 2026.4.1
  2. MKuula commented on Nov 10, 2026

    @MKuula

    I'm not sure about this but perhaps the last update flipped the 'Use Environments Extension' toggle on? There is a mention in the Python settings that the default value changed.

    Flipping this off fixes the problem temporarily until the real fix comes. Or using the debugger.

  3. BeniNobel commented on Nov 10, 2026

    @BeniNobel
    Author

    Thanks to everyone who reproduced this. A Windows report shows the same literal quotes in the script path, so this affects both PowerShell and Zsh.

    I looked into the timing. The Python extension has passed a pre-quoted script path to Python Environments since #25405. Python Environments #1946 later changed terminal execution to quote arguments for Zsh and PowerShell. Together, those changes appear to produce the literal quotes in these reports.

    That later change shipped in Python Environments 1.42.0 on November 4, the same evening my installation updated. This strongly suggests the update exposed the mismatch.

    PR #26275 addresses it by passing the script path without added quotes.

  4. fung19942003 commented on Nov 12, 2026

    @fung19942003

    I have a similar issue on Windows with Git Bash as the VS Code
    default terminal.

    When I click “Run Python File”, the script path is passed with
    double quotes inside single quotes:

    python.exe '"C:/path with spaces/script.py"'

    Python then reports: [Errno 22] Invalid argument.

    Running the same file manually with correctly quoted paths works.
    Ctrl+F5 with Python Debugger also works.

    Shell: Git Bash
    Python: 3.14
    Vscode version : 1.145.2 (c4453f8ea430795f941c1b2ff6c9321135a74a02)

  5. edvilme commented on Nov 13, 2026

    @edvilme

    Hello, we are actively looking at this issue and reviewing the proposed PR for a fix

  6. BeniNobel commented on Nov 14, 2026

    @BeniNobel
    Author

    Thanks for looking into this. #26275 and #26276 both address the quoting issue in executeUsingExtension, so I wanted to flag the overlap.

    #26275 includes regression coverage for all three Run Python File commands, including the top-right icon, across several path cases. I also verified the patched extension inside VS Code on macOS. That check does not establish PowerShell behavior, but the test coverage may be useful when finalizing the fix.

  7. Roadscript commented on Nov 16, 2026

    @Roadscript

    I reproduced this issue on macOS and performed several controlled experiments that revealed an additional behavior potentially relevant to the investigation: the failure depends on the Python Environments extension's lifecycle, not just whether it is installed or enabled.

    Environment

    • macOS, Apple Silicon (M1 Pro)
    • VS Code version: 1.146.0
    • Python Environments: 1.42.0
    • Python: 3.15.2 (Homebrew)
    • Shells tested: Bash and Zsh
    • Project directory: ~/Desktop/Test test/
    • Script: test.py, containing only print("This works")
    • Execution command: Python: Run Python File in Terminal

    VS Code Environment

    Version: 1.146.0
    Commit: 69047191fc427f2f92828279aae1d90d8eeda7ab
    Date: 2026-11-10T19:27:51Z
    Electron: 43.8.6
    ElectronBuildId: 15893748
    Chromium: 150.0.7871.250
    Node.js: 24.22.1
    V8: 15.0.245.31-electron.0
    @github/copilot: 1.0.108-0
    @github/copilot-sdk: 1.0.30-preview.0
    OS: Darwin arm64 27.3.0
    

    Relevant extensions:

    • Python Environments (ms-python.vscode-python-envs): 1.42.0
    • Python (ms-python.python): Version not yet recorded

    All experiments were performed using VS Code 1.146.0 on macOS arm64.

    1. Reproduction with Python Environments enabled

    With Python Environments enabled after a fresh VS Code launch, execution fails.

    The Python Environments output contains:

    [info] [SYS_GET] uri=/Users/kevenli/Desktop/Test test/test.py, normalizedKey=/Users/kevenli/Desktop/Test test/test.py, project=/Users/kevenli/Desktop/Test test, projectKey=/Users/kevenli/Desktop/Test test, mapKeys=[/Users/kevenli/Desktop/Test test], directHit=false, projectHit=true, fallbackToGlobal=false
    [info] runInTerminal: executeCommand /opt/homebrew/bin/python3 '"/Users/kevenli/Desktop/Test test/test.py"'
    

    The script path is correctly identified during environment lookup, but the execution command contains literal double quotes inside a single-quoted argument.

    Python subsequently fails with [Errno 2] No such file or directory.

    2. Disabling Python Environments fixes execution

    With Python Environments disabled and the main Python extension still enabled, the same command succeeds:

    /opt/homebrew/bin/python3 "/Users/kevenli/Desktop/Test test/test.py"

    Output:

    This works
    

    I also tested a virtual environment located inside the same directory containing spaces:

    "/Users/kevenli/Desktop/Test test/.venv/bin/python" "/Users/kevenli/Desktop/Test test/test.py"

    This succeeds as well.

    Therefore, the failure is reproducible with both a global Homebrew interpreter and a virtual environment, while both work when Python Environments is disabled.

    3. Unexpected extension lifecycle behavior

    I observed the following sequence:

    Configuration Result
    Fresh VS Code launch, Python Environments enabled Fails
    Disable Python Environments and reload Works
    Re-enable Python Environments without fully quitting VS Code Still works
    Terminate existing terminals and execute in a fresh terminal Still works
    Completely quit and restart VS Code Fails again

    The particularly interesting observation is that re-enabling Python Environments does not immediately restore the failure.

    During successful executions after re-enabling the extension, the Python Environments output still records [SYS_GET] environment lookups, but I did not observe a corresponding runInTerminal: executeCommand entry.

    After a complete VS Code restart, the malformed runInTerminal: executeCommand entry returns alongside the execution failure.

    This suggests that the execution path or handler selection may differ depending on extension initialization state. I have not verified the internal registration mechanism, so this remains a hypothesis.

    4. Additional observations

    • The issue reproduces with both Bash and Zsh.
    • It reproduces with a minimal Python script, independent of project code.
    • Manual execution from the integrated terminal works.
    • A directory without spaces works.
    • The Python extension's debug output includes Attempting to run Python file undefined, although I have not established whether that is relevant.

    Potential investigation angle: The difference between a fresh extension-host initialization and disabling/re-enabling Python Environments may help identify how the runInTerminal execution path is selected.

    I hope these observations are useful when validating the proposed fixes, particularly the extension lifecycle behavior.

  8. Roadscript commented on Nov 16, 2026

    @Roadscript

    Follow-up: Python Environments 1.45.2026111301 (Pre-release)

    After completing the investigation with Python Environments 1.42.0, I switched to the pre-release version 1.45.2026111301 and restarted VS Code.

    Using the same project directory containing spaces (~/Desktop/Test test/), the Python script now executes successfully.

    Generated command:

    "/Users/kevenli/Desktop/Test test/.venv/bin/python" "/Users/kevenli/Desktop/Test test/test.py"

    Output:

    This works
    

    The Python Environments output records a [SYS_GET] environment lookup but does not show a corresponding runInTerminal: executeCommand entry.

    This differs from the failing behavior observed with version 1.42.0, where the malformed command was explicitly logged by runInTerminal.

    Important limitation: Although execution succeeds with the pre-release installed and enabled, I have not confirmed whether terminal execution is being handled by Python Environments or by the main Python extension.

    Therefore, this result demonstrates successful execution in the newer configuration, but does not independently establish that the quoting defect has been fixed inside Python Environments.

  9. mcfunthomas commented on Nov 16, 2026

    @mcfunthomas

    Confirmed reproduction on macOS — Conda environment

    I encountered the same issue on 16 November 2026 while running a simple Python script in VS Code.

    Environment:

    • OS: macOS (Apple Silicon)

    • Shell: Zsh

    • Python: 3.11.14

    • Environment manager: Miniconda

    • Conda environment: od_zera_do_ai

    • Python Environments extension: v1.42.0 and v1.45.2026111601 (both tested)

    • Project stored on an external volume, with spaces in the directory path

    Observed behaviour:

    Both Run Python File and Run Python File in Dedicated Terminal generated a command with incorrectly nested quotation marks:

    /Users/<username>/opt/miniconda3/envs/od_zera_do_ai/bin/python '"/Volumes/BckUp3/.../VSC Test/hello.py"'

    Resulting error:

    can't open file '/Volumes/BckUp3/.../VSC Test/"/Volumes/BckUp3/.../VSC Test/hello.py"': [Errno 2] No such file or directory

    Tests and results:

    Test | Result -- | -- Run Python File | Failed Run Python File in Dedicated Terminal | Failed Run as Task | Passed Manual execution (python hello.py) | Passed Disable Python Environments extension and restart VS Code | Passed Run with original Conda interpreter after restart | Passed Re-enable/update to Python Environments v1.45.2026111601 | Failed again

    Workaround confirmation:

    Disabling the Python Environments extension and restarting VS Code resolved the issue without changing the Python script, its location, or the Conda environment.

    After restarting, the script executed successfully using the original interpreter:

    Python 3.11.14
    .../miniconda3/envs/od_zera_do_ai/bin/python

    Conclusion:

    The issue reproduces with both tested Python Environments extension versions (v1.42.0 and v1.45.2026111601). Disabling the extension remains an effective workaround in this configuration.

    Hope these additional reproduction details help with debugging and regression testing.

  10. edvilme commented on Nov 16, 2026

    @edvilme

    Hello,
    We are aware of the issue which should be fixed by #26276. We will continue to do additional manual testing to ensure it is effectively fixed. Thanks for all the additional details

  11. added a commit that references this issue on Nov 16, 2026
    dc54b81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions