'env: python3.9: No such file or directory

I have some python code formatters as git pre-commit hook and I have changed my python version as

brew list | grep python
[email protected]
[email protected]

brew unlink [email protected]
brew unlink [email protected]
brew link [email protected]

python -V
Python 3.7.9

and know seems something get broken and on git commit I get env: python3.9: No such file or directory, so what is env? and how I can edit it to use [email protected]?



Solution 1:[1]

In .git/hooks/pre-commit I have

#!/usr/bin/env python3.9

and running pre-commit install fixed it to #!/usr/bin/env python3.7

Solution 2:[2]

Even though @mrgloom answer pointed me in the right direction, it wasn't good enough to solve my situation.

This error just happened to me after I upgraded from Ubuntu 21.10 to 22.04. It clearly looks like the installed Python version isn't Python 3.9 anymore. So I quickly checked that right now I have 3.10.

Simply editing the .git/hooks/pre-commit with Python3.10 wasn't enough.

What worked for me was reinstall pre-commit: https://pre-commit.com/#install

So, you can either run pip install pre-commit or brew install pre-commit.

Solution 3:[3]

For me, I deleted the old virtual environment and re-Creating it and worked:

$ deactivate
$ python3 -m venv env
$ source env/bin/activate

Hope this would solve your problem, thank you!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mrgloom
Solution 2 xarlymg89
Solution 3 Ericgit