我刚刚在Windows环境下安装了Ubuntu18.04.4LTS。当我运行一个在bash终端中不存在的命令(例如,如果我意外地向ls添加了一个S)时,我会得到以下错误:
$ lss
-bash: /usr/bin/python: No such file or directory错误是正确的,我只安装了python3:
$ ls /usr/bin/python*
/usr/bin/python3 /usr/bin/python3-jsonpatch /usr/bin/python3-jsonschema /usr/bin/python3.6m
/usr/bin/python3-jsondiff /usr/bin/python3-jsonpointer /usr/bin/python3.6 /usr/bin/python3m从以前使用Ubuntu时,我记得消息应该是“程序'lss‘可以在以下软件包中找到:”我不再需要该消息了,我不想仅仅为了让它正常工作而安装python2 (这个问题有通过安装py2来解决问题的答案.)。
如果不安装python2,将python 3符号链接为2,或者变得完美,再也不做排字,就能修复这个问题吗?
理想情况下,我可以将“命令不存在”脚本移植到python3或disable完全。
发布于 2020-03-25 22:59:14
结果,我在bashrc中直接用一个名为command_not_found_handle的函数(巴什特征)覆盖了这个函数:
# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found ]; then
function command_not_found_handle {
# check because c-n-f could've been removed in the meantime
if [ -x /usr/lib/command-not-found ]; then
/usr/bin/python /usr/lib/command-not-found -- $1
return $?
else
return 127
fi
}
fi这段代码不再有必要了(是吗?)移除它解决了我的问题--现在旧的“可以在下面的包中找到”输出。
完整性:如果我想跳过python代码和命令不存在的简单输出,可以将其放在bashrc中:
function command_not_found_handle {
echo Command not found: $1
return 127
}发布于 2020-03-19 13:52:41
Python3并不是python2的替代品。您需要一个python3版本的lss。
如果我是你,我会更新lss。这是一个独立的脚本,源代码可以在github上找到。1很明显:
print 'Usage:', __file__, '/path/to/dir'"print“在使用python3时需要使用"(”和")“。我会将脚本放入一个名为lss3的文件或类似的文件中,并使用python3 lss3查找和修复错误。
https://askubuntu.com/questions/1218457
复制相似问题