错误的解释器没有这样的文件或目录 /usr/bin/python
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47822600/
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
bad interpreter no such file or directory /usr/bin/python
提问by vb.net
I created script python and I moved it to /usr/bin and I named the script by sdfgdgh without .py and I write in script this code
我创建了脚本 python 并将其移至 /usr/bin 并通过 sdfgdgh 命名脚本而不使用 .py 并在脚本中编写此代码
#! /usr/bin/python
print("worked")
and I was given the script chmod +x
but when I type in terminal sdfgdgh give me the error :
我得到了脚本 chmod +x
但是当我输入终端 sdfgdgh 给我错误:
bad interpreter no such file or directory /usr/bin/python
错误的解释器没有这样的文件或目录 /usr/bin/python
why and what is the solution ?
为什么?解决方案是什么?
回答by running.t
The problem is with your python instalation. Probably your /usr/bin/python
either does not exist at all or it is dead symbolic link pointing to non existing python.
问题在于您的 python 安装。可能你的/usr/bin/python
要么根本不存在,要么是指向不存在的python的死符号链接。
So first solution is to check if /usr/bin/python
exists. If so check if it's not dead link and if it is, fix the link to point to existing python intepretter:
所以第一个解决方案是检查是否/usr/bin/python
存在。如果是这样,请检查它是否不是死链接,如果是,请修复链接以指向现有的 python 解释器:
cd /usr/bin
sudo ln -fs <full_path_to_existing_python_binary> python
If you can't or don't want to change /usr/bin/python
but you have python installed and it's location is recognized by system (i.e. calling python
from shell works) you can try changing your script as a workarround:
如果您不能或不想更改/usr/bin/python
但您安装了 python 并且它的位置被系统识别(即python
从 shell调用),您可以尝试更改脚本作为解决方法:
#! /usr/bin/env python
print("worked")
This way your script will use python as an interpetter regardless real python location as long as it is in your PATH.
这样你的脚本就会使用 python 作为 interpetter,而不管真正的 python 位置,只要它在你的 PATH 中。
回答by Praveen Kalarikkal
Simply run this :-
只需运行这个:-
sudo bash -c "test -e /usr/bin/python || (apt -qqy update && apt install -qy python-minimal)
回答by gpresland
You can install python with:
您可以使用以下命令安装 python:
apt install python
After that, the python
command will work.
之后,该python
命令将起作用。