Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3.7: command not found #810

Closed
cancan101 opened this issue Aug 8, 2018 · 18 comments
Closed

python3.7: command not found #810

cancan101 opened this issue Aug 8, 2018 · 18 comments
Labels

Comments

@cancan101
Copy link

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: pyenv/pyenv-virtualenv#206

@asottile
Copy link
Member

asottile commented Aug 8, 2018

what does python3.7 -c 'print("hello world")' say?

@cancan101
Copy link
Author

pyenv: python3.7: command not found

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

@asottile
Copy link
Member

asottile commented Aug 8, 2018

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 😆

@asottile
Copy link
Member

closing this since this is likely an issue with your setup @cancan101

If it's not, feel free to comment / reopen!

@thomasfowler
Copy link

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.

@mty2015
Copy link

mty2015 commented Jul 25, 2019

Create a symbolic link

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

@mzack5020
Copy link

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.

You're awesome. Worked like a charm

@gvizquel
Copy link

In my case I am working with pipenv and I get this error:

python ('/.../.local/share/virtualenvs/guvniOjd/bin/python3.7m', '-mvirtualenv', '/.../.cache/pre-commit/repohfwzvhx1/py_env-python3.7m', '-p', 'python3.7m')

python3.7m -c 'print("hello world")'
hello world

I would appreciate any help.

Thanks

@asottile
Copy link
Member

paste your full error message -- if it doesn't exactly match the output of OP's then it's a different issue

@gvizquel
Copy link

An unexpected error has occurred: CalledProcessError: command: ('/.../.local/share/virtualenvs/guvniOjd/bin/python3.7m', '-mvirtualenv', '/.../.cache/pre-commit/repohfwzvhx1/py_env-python3.7m', '-p', 'python3.7m')
return code: 1
expected return code: 0
stdout:
    RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.7m'

Thanks

@asottile
Copy link
Member

yeah that's a completely different error message as I suspected, what does virtualenv venv -p python3.7m give you? (if that fails, please create an issue on pypa/virtualenv)

@gvizquel
Copy link

virtualenv venv -p python3.7m
Running virtualenv with interpreter /usr/local/bin/python3.7m
Using base prefix '/usr/local'
/usr/lib/python3/dist-packages/virtualenv.py:1090: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
New python executable in /.../venv/bin/python3.7m
Also creating executable in /.../venv/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.

@asottile
Copy link
Member

use the same version of virtualenv (the error above is from virtualenv 20.x, your output is from virtualenv<20)

@asottile
Copy link
Member

nevermind I'll do it for you

@asottile
Copy link
Member

here's the upstream issue @gvizquel -- you can work around by installing virtualenv<20 alongside pre-commit

@gvizquel
Copy link

gvizquel commented Mar 23, 2020

Thank you very much @asottile a will try it

It is working as expected...

@JackTheMico
Copy link

@thomasfowler Thank you very much! I googled this about a hour, finally make it worked with your solution.
This should be recorded somewhere

@pre-commit pre-commit locked as resolved and limited conversation to collaborators May 7, 2022
@asottile
Copy link
Member

asottile commented May 7, 2022

@JackTheMico please don't bump 2 year old issues with a "thanks" message -- that's what the thumbs up button is for

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

7 participants