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.

Error: spawn <python interpreter> ENOENT on test discovery when `"python.testing.cwd"` is set

See original GitHub issue

I have searched stackoverflow as well as GitHub issues here and found some related issues but nothing conclusive or helpful.

Environment data

  • VS Code version: 1.54.3
  • Extension version (available under the Extensions sidebar): v2021.3.658691958
  • OS and version: macOS Big Sur 11.2.3
  • Python version (& distribution if applicable, e.g. Anaconda): all
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): n/a
  • Relevant/affected Python packages and their versions: pytest | unittest
  • Relevant/affected Python-related VS Code extensions and their versions: vscode-python v2021.3.658691958
  • Value of the python.languageServer setting: pylance

Expected behaviour

python process for test discovery would spawn successfully or produce more descriptive error.

Actual behaviour

python /Users/patrick/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /Users/patrick/dev/vscode-test -s --cache-clear
Test Discovery failed: 
Error: spawn /Users/patrick/.pyenv/shims/python ENOENT

Steps to reproduce:

  1. Delete/move ~/.vscode for fresh vscode user env.
  2. Create simple python project with one pytest test and open vscode to folder with only the python extension and pytest auto discovery enabled.
  3. Observe output in Python Test Log listed below.
  4. Copy/paste command line from Python Test Log into macOS terminal.
  5. Observe process runs successfully and discovers pytest test.

*NOTE: I am unable to reproduce this problem on a clean system. But, it occurs for any python 3 version installed via system, brew, and pyenv regardless of whether the vscode project points to a symlink or executable.

Logs

Output for Python in the Output panel

User belongs to experiment group 'pythonaacf'
User belongs to experiment group 'pythonSendEntireLineToREPL'
User belongs to experiment group 'pythonNotDisplayLinterPrompt'
User belongs to experiment group 'pythonTensorboardExperiment'
User belongs to experiment group 'ShowExtensionSurveyPrompt - enabled'
User belongs to experiment group 'CollectLSRequestTiming - control'
> conda --version
> conda info --json
> pyenv root
> python3.7 ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> ~/.pyenv/shims/python ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> pyenv root
> pyenv root
> pyenv root
> pyenv root
> pyenv root
> pyenv root
Starting Pylance language server.
Python interpreter path: ~/.pyenv/shims/python
> ~/.pyenv/shims/python ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/dev/vscode-test -s --cache-clear
cwd: api
> ~/.pyenv/shims/python ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/dev/vscode-test -s --cache-clear
cwd: api
Error 2021-03-20 20:11:59: Failed to parse discovered Test [Error: spawn /Users/patrick/.pyenv/shims/python ENOENT
	at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
	at onErrorNT (internal/child_process.js:469:16)
	at processTicksAndRejections (internal/process/task_queues.js:84:21)] {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn /Users/patrick/.pyenv/shims/python',
  path: '/Users/patrick/.pyenv/shims/python',
  spawnargs: [
    '/Users/patrick/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/testing_tools/run_adapter.py',
    'discover',
    'pytest',
    '--',
    '--rootdir',
    '/Users/patrick/dev/vscode-test',
    '-s',
    '--cache-clear'
  ]
}
> conda --version
> ~/.pyenv/shims/python ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import pytest"
> ~/.pyenv/shims/python ~/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/pyvsc-run-isolated.py -c "import pytest"
Error 2021-03-20 20:12:00: Python Extension: displayDiscoverStatus [TypeError: Cannot read property 'uri' of undefined
	at /Users/patrick/.vscode/extensions/ms-python.python-2021.3.658691958/out/client/extension.js:9:495273]

Output for Python Test Log in the Output panel

python /Users/patrick/.vscode/extensions/ms-python.python-2021.3.658691958/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /Users/patrick/dev/vscode-test -s --cache-clear
Test Discovery failed: 
Error: spawn /Users/patrick/.pyenv/shims/python ENOENT

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:22

github_iconTop GitHub Comments

1reaction
patrickkiddcommented, May 25, 2021

Note you’ll need to Reload for changes in the setting to take affect, the cwd in python output panel doesn’t change unless we reload. Does removing the setting and reloading make a difference? For me it does fix the spawn enoet issue.

Ah, that’s right. Reloading the window did fix the spawn problem on both projects.

I have no idea where ${workspaceDir} came from, it isn’t anywhere in my project folder or the extensions folder. Though it did appear when I removed the "python.testing.cwd" from my settings. It looks like the extension always prints cwd <whatver-it-is-set-to> on a new line.

And - setting it to ${workspaceFolder}/api did fix the cwd problem! Good grief…cheers for the help!

0reactions
karrtikrcommented, May 25, 2021

Anyways this would be a different issue, do you mind opening a new one in case if you still face issues with it? Please provide all of the Python, Python Test log, and debug console logs as it really helps, thanks.

I have mentioned in https://github.com/microsoft/vscode-python/issues/11669 that we should update the docs for python.testing.cwd, that it should only carry absolute paths. As it seems you were trying to use relative paths instead which failed. Closing in favor of https://github.com/microsoft/vscode-python/issues/11669.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode on discover tests Error: spawn python ENOENT
ENOENT Generally means that it's an invalid path, but the path seems perfectly fine. $echo $PATH /Users/<username>/apps/project/venv/bin.
Read more >
Changelog — Python 3.11.1 documentation
gh-98713: Fix a bug in the typing tests where a test relying on CPython-specific implementation details was not decorated with @cpython_only and was...
Read more >
Debugging configurations for Python apps in Visual Studio Code
The path to the python executable is incorrect: check the path of your selected interpreter by running the Python: Select Interpreter command and...
Read more >
vscode launch.json python path - You.com | The AI Search ...
How to correctly set PYTHONPATH for Visual Studio Code. Asked Dec 6, 2018 • 84 votes 13 answers ... VSCode on discover tests...
Read more >
VSCode on discover tests Error: spawn python ... - 七牛云
将 "python.testing.cwd": "${workspaceFolder}" 添加到 settings.json 中,为我解决了问题。 Bhavani Ravi. 发布于 2022-05-24. 0 人赞同.
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