pre-commit: python3.7: command not found

If I set language_version: python3.7 rather than language_version: python3, I get the following error. I am using pyenv-virtualenv:

An unexpected error has occurred: CalledProcessError: Command: ('/Users/alex/.pyenv/versions/3.7.0/envs/xxxx/bin/python', '-mvirtualenv', '/Users/alex/.cache/pre-commit/repoxj_919t6/py_env-python3.7', '-p', 'python3.7')
Return code: 127
Expected return code: 0
Output:
repos:
    Running virtualenv with interpreter /Users/alex/.pyenv/shims/python3.7

Errors:
    pyenv: python3.7: command not found

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

This may be related to: https://github.com/pyenv/pyenv-virtualenv/issues/206

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

Just adding this here for anyone that comes across this issue.

When you create a virtualenv using, for example, pyenv virtualenv 3.7.0 example_venv, the command python3.7 will not work once that virtualenv is activated.

In order to make the command python3.7 work in an activated virtualenv, you need to tell pyenv virtualenv what additional commands too use.

So, to correctly setup the virtualenv to work with pre-commit, run the command as:

pyenv virtualenv -p python3.7 3.7.0 example_venv

This should resolve the issue reported.

Create a symbolic link

cd /Users/alex/.pyenv/versions/3.7.0/bin/
ln -s python3 python3.7

Looks like your python3.7 is misconfigured / not installed.

I haven’t worked much with pyenv myself but I believe you need to do something like pyenv install 3.7.0 and pyenv global 3.7.0 (or something of the sort? maybe the second one isn’t necessary?)

pre-commit itself doesn’t have any direct integration with pyenv, though it is known to work with it fine as long as you have things set up properly – notably, pre-commit will call virtualenv -p $language_version and if the python referenced by language_version isn’t functional – well then you’ll see what you’re seeing 😆