env: python3.9: No such file or directory
Asked Answered
P

3

6

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]?

Priestley answered 3/8, 2021 at 10:53 Comment(4)
I'd sugges to check code for the pre-commit hooks as most of the Python scripts start with a shebang line like #!/usr/bin/env python. You might have something like #!/usr/bin/env python3.9 there. You can try to change it to #!/usr/bin/env python3.7 but I cannot assure you it will work without problems, as some features of Python 3.9 might be used by scripts.Brote
Regarding the env it's a shell command that starts programs in a modified environment. You can check some info about it running command man env on Linux/Unix.Brote
linux.die.net/man/1/envTwi
(a guess) if you're using [pre-commit.com] run pre-commit install and it will fix your shebang to point at your new global python versionBattista
P
4

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

Priestley answered 10/8, 2021 at 15:9 Comment(0)
B
0

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.

Burnight answered 27/4, 2022 at 8:48 Comment(0)
T
0

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!

Trinitroglycerin answered 31/5, 2022 at 9:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.