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.

failed to find interpreter when running black via pre-commit

See original GitHub issue

I am suddenly having issues running black via pre-commit. Other pre-commit hooks work just fine. I have the following in my pre-commit config:

-   repo: https://github.com/psf/black
    rev: stable
    hooks:
    - id: black
      language_version: python3.7

I am using Python version 3.7.6 with pyenv. This setup has worked just fine for a long time.

Now, when committing my changes, I get the following error:

### version information


pre-commit version: 2.9.3
sys.version:
    3.9.1 (default, Jan  6 2021, 06:04:49) 
    [Clang 12.0.0 (clang-1200.0.32.28)]
sys.executable: /usr/local/Cellar/pre-commit/2.9.3/libexec/bin/python3
os.name: posix
sys.platform: darwin


### error information


An unexpected error has occurred: CalledProcessError: command: ('/usr/local/Cellar/pre-commit/2.9.3/libexec/bin/python3', '-mvirtualenv', '/Users/levinotik/.cache/pre-commit/repoc_gsawtf/py_env-python3.7', '-p', 'python3.7')
return code: 1
expected return code: 0
stdout:
    RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.7'
    
stderr: (none)

Traceback (most recent call last):
  File "/usr/local/Cellar/pre-commit/2.9.3/libexec/lib/python3.9/site-packages/pre_commit/error_handler.py", line 65, in error_handler
    yield
  File "/usr/local/Cellar/pre-commit/2.9.3/libexec/lib/python3.9/site-packages/pre_commit/main.py", line 347, in main
    return hook_impl(
  File "/usr/local/Cellar/pre-commit/2.9.3/libexec/lib/python3.9/site-packages/pre_commit/commands/hook_impl.py", line 217, in hook_impl
    return retv | run(config, store, ns)
  File "/usr/local/Cellar/pre-commit/2.9.3/libexec/lib/python3.9/site-packages/pre_commit/commands/run.py", line 402, in run
    install_hook_envs(hooks, store)
  File "/usr/local/Cellar/pre-commit/2.9.3/libexec/lib/python3.9/site-packages/pre_commit/repository.py", line 206, in install_hook_envs
    _hook_install(hook)
  File "/usr/local/Cellar/pre-commit/2.9.3/libexec/lib/python3.9/site-packages/pre_commit/repository.py", line 82, in _hook_install
    lang.install_environment(
  File "/usr/local/Cellar/pre-commit/2.9.3/libexec/lib/python3.9/site-packages/pre_commit/languages/python.py", line 202, in install_environment
    cmd_output_b(*venv_cmd, cwd='/')
  File "/usr/local/Cellar/pre-commit/2.9.3/libexec/lib/python3.9/site-packages/pre_commit/util.py", line 154, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/usr/local/Cellar/pre-commit/2.9.3/libexec/bin/python3', '-mvirtualenv', '/Users/levinotik/.cache/pre-commit/repoc_gsawtf/py_env-python3.7', '-p', 'python3.7')
return code: 1
expected return code: 0
stdout:
    RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.7'
    
stderr: (none)

I’m not sure how to resolve this or whether this is actually an upstream issue in black. Any ideas? Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
levinotikcommented, Jan 19, 2021

Gotcha. Makes sense. Thanks so much for helping even though this wasn’t a pre-commit issue.

1reaction
levinotikcommented, Jan 19, 2021

Thanks a lot, really appreciate it. Interesting, I had language_version: python3.7 in my black settings in pre-commit-config.yaml. Changing that to language_version: python3 does seem to resolve the issue!

Here’s what I get for the things you asked about:

$ cd / && python3.7 --version
direnv: unloading
pyenv: python3.7: command not found

The `python3.7' command exists in these Python versions:
  3.7.6
  3.7.7

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.

and

$ virtualenv venv -ppython3.7
RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.7'
Read more comments on GitHub >

github_iconTop Results From Across the Web

failed to find interpreter for Builtin discover of python_spec ...
While trying to use pre-commit hooks, I am experiencing some difficulties, including the latest Lava-nc release by Intel in .tar.gz format pip ...
Read more >
pre-commit
We run our hooks on every commit to automatically point out issues in code such as missing semicolons, trailing whitespace, and debug statements....
Read more >
Pycharm does not use virtualenv pep8 for git-hooks : PY-12988
I have pre-commit hook when i commit using Pycharm - it not using PATH from virtualenv (default project interpreter) and use system pep8...
Read more >
Contributing to the code base — pandas 1.5.2 documentation
Using hypothesis #. Hypothesis is a library for property-based testing. Instead of explicitly parametrizing a test, you can describe all valid inputs and...
Read more >
Python HOW: Using Poetry, Make, and pre-commit-hooks to ...
If the prerequisite interpreter path doesn't exist, you will get an error when running the venv target. Makefile > line 12 is where...
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