Skip to content

Python Environments extension causes incorrectly quoted file paths when running Python files on macOS #1996

Open

Description

@ba46174617

I used chatgpt to help me go through this issue and the report below is fully generated by chatgpt which I copied and pasted.

VS Code Python Environments extension generates incorrectly quoted file path when running Python scripts on macOS

Description

When running a Python script using VS Code's Run Python File command, the Python Environments extension appears to cause the file path to be incorrectly quoted.

The Python interpreter then raises a FileNotFoundError ([Errno 2] No such file or directory).

Running the same script manually in the VS Code terminal works correctly.

Disabling the Microsoft Python Environments extension for the workspace resolves the issue.

Environment

  • Operating system: macOS Monterey 12.7.6
  • Python interpreter: /opt/anaconda3/bin/python
  • Python version: 3.13.5
  • Shell: zsh
  • Python environment: Anaconda (base)
  • Editor: Visual Studio Code
  • Affected extension: Microsoft Python Environments (ms-python.vscode-python-envs)
  • Python Environments: 1.42.0
  • Python: 2026.10.0
  • Visual Studio Code version: 1.145.2

Steps to Reproduce

  1. Open a Python project in VS Code.
  2. Ensure the Microsoft Python and Python Environments extensions are enabled.
  3. Select /opt/anaconda3/bin/python as the Python interpreter.
  4. Create a Python script inside a folder containing spaces, for example Leetcode Problems/Min Depth of Binary Tree.
  5. Open the script and click Run Python File.
  6. Observe that Python reports No such file or directory.
  7. Disable the Python Environments extension for the workspace and reload VS Code.
  8. Run the same file again.

Actual Behavior

The Python extension logs show a command resembling:

/opt/anaconda3/bin/python '"/Users/.../Leetcode Problems/Min Depth of Binary Tree"'

The single quotes cause the inner double quotes to be passed as literal characters in the filename.

Python then fails to locate the script.

Expected Behavior

VS Code should generate a correctly quoted command:

/opt/anaconda3/bin/python "/Users/.../Leetcode Problems/Min Depth of Binary Tree"

The script should execute successfully.

Workaround

Disabling the Microsoft Python Environments extension for the workspace resolves the issue.

After disabling it, VS Code generates the correctly quoted command and the script executes successfully.

Additional Information

  • The problem also occurs when selecting Run Python File in Dedicated Terminal.
  • Running the script manually works correctly.
  • Renaming the script to include a .py extension did not resolve the issue.
  • Disabling VS Code terminal shell integration did not resolve the issue.
  • The Python Output logs also intermittently displayed Unable to find workspace for given file.

The issue appears to involve an interaction between the Python Environments extension and the Python execution command.

Extension Logs

Before disabling Python Environments:

[info] Send text to terminal: /opt/anaconda3/bin/python '"/Users/.../Leetcode Problems/Min Depth of Binary Tree"'

After disabling Python Environments, the generated command used correct quoting and the script ran successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions