bash Python /usr/bin/env:错误的解释器:不是目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30796142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:11:40  来源:igfitidea点击:

Python /usr/bin/env: bad interpreter: Not a directory

pythonlinuxbash

提问by lilouch

I did a mistake. I installed Python 3 and then I did the following command in order to have the defaut version Python as Python3

我犯了一个错误。我安装了 Python 3,然后我执行了以下命令,以便将默认版本 Python 作为 Python3

sudo ln -fs /opt/Python-3.4.1/python /usr/bin/python

But I wanted to come back to the python2.7 and I did

但我想回到python2.7,我做到了

sudo ln -fs /usr/bin/python2.7/python /usr/bin/python

Now, When I want to run a bash script with python inside, I have this following error:

现在,当我想运行带有 python 的 bash 脚本时,出现以下错误:

/usr/bin/env: bad interpreter: Not a directory

/usr/bin/env: 错误的解释器:不是目录

When I run this command:

当我运行此命令时:

ls -l /usr/bin/env

I have this result in red:

我的结果是红色的:

lrwxrwxrwx 1 root root 25 Jun 12 13:37 /usr/bin/env -> /usr/bin/python2.7/python

lrwxrwxrwx 1 root root 25 Jun 12 13:37 /usr/bin/env -> /usr/bin/python2.7/python

Indeed, when I go in this directory, I don't have the env executable anymore but a broken link.

事实上,当我进入这个目录时,我不再有 env 可执行文件,而是一个断开的链接。

I didn't find a solution on the internet.

我没有在互联网上找到解决方案。

Could you help me ? I begin to feel bad about my mistake.

你可以帮帮我吗 ?我开始为我的错误感到难过。

Thanks

谢谢

回答by lilouch

Okey, I solved my issue by reinstalling this env file.

好的,我通过重新安装这个 env 文件解决了我的问题。

sudo apt-get install --reinstall coreutils

Then thanks to this post in Why do people write the #!/usr/bin/env python shebang on the first line of a Python script?I know better how to switch between version and do not do the same mistake anymore.

然后感谢这篇文章为什么人们在 Python 脚本的第一行写 #!/usr/bin/env python shebang?我更清楚如何在版本之间切换并且不再犯同样的错误。