在ubunutu 16.04上使用源码编译安装python3.8之后出现了这个bug。任意输入不存在的命令,会跳出来一个python的异常
报错详情:
root@Lee:/var/log# junk
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 27, in <module>
from CommandNotFound.util import crash_guard
ModuleNotFoundError: No module named 'CommandNotFound'
搜索标题中的文字,会得到cnblogs上的一篇文章:
https://www.cnblogs.com/finlu/p/11588870.html
这篇答案会指向 https://askubuntu.com/questions/766246/missing-package-commandnotfound
解决方案是。。删除掉python3。。可是我不想删除刚刚装好的python行不行。
sudo apt-get remove --purge python3*
sudo apt auto remove
继续找了好久,发现有各种各样的解决方案(下面两个是不太靠谱的):
- 不要使用源码安装python
- 将usr/bin里面的python3符号链接恢复到指向系统自带的python3.5
最后找到一个靠谱的:https://askubuntu.com/questions/952302/python-modulenotfounderror-commandnotfound
Add one more answer, as I also encountered this issue and happened to solve it.
This issue happened when I installed python3.7 from source.
Check /usr/lib/command-not-found file, it is trying to find module CommandNotFound
, which is NOT shipped with python3.7 but DOES with Ubuntu under directory /usr/lib/python3/dist-packages
.
What we need to do is adding the directory to python import path:
vi .bashrc
(or .profile)- add line
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.7/site-packages:/usr/lib/python3/dist-packages
Pay attention that you may need to change the/usr/local/lib/python3.7/site-packages
to your own directory. - exit and
source .bashrc
(or .profile)