env: python3.9: 没有那个文件或目录

env: python3.9: No such file or directory

我有一些 python 代码格式化程序作为 git 预提交挂钩,我已经将我的 python 版本更改为

brew list | grep python
python@3.7
python@3.9

brew unlink python@3.7
brew unlink python@3.9
brew link python@3.7

python -V
Python 3.7.9

并且知道似乎有些东西坏了,在 git 提交时我得到 env: python3.9: No such file or directory,那么 env 是什么?以及如何编辑它以使用 python@3.7?

.git/hooks/pre-commit我有

#!/usr/bin/env python3.9

和 运行 pre-commit install 将其固定为 #!/usr/bin/env python3.7

尽管@mrgloom 的回答为我指明了正确的方向,但还不足以解决我的问题。

这个错误是我从 Ubuntu 21.10 升级到 22.04 后才发生的。很明显,安装的 Python 版本不再是 Python 3.9。所以我很快检查了一下我现在有 3.10.

仅使用 Python3.10 编辑 .git/hooks/pre-commit 是不够的。

对我有用的是重新安装 pre-commit:https://pre-commit.com/#install

因此,您可以 运行 pip install pre-commitbrew install pre-commit

对我来说,我删除了旧的虚拟环境并re-Creating它并且工作:

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

希望这能解决您的问题,谢谢!