python - Arbitrary strings in bash throw python errors?
问题描述
Something in my setup of my shell causes arbitrary strings like "krmpfl" or "u45g5svtJ7" to create a Python error:
$> krmpfl
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 28, in <module>
from CommandNotFound import CommandNotFound
File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in <module>
from CommandNotFound.db.db import SqliteDatabase
File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
I would expect bash (and not python!) to throw an error of the kind "Unknown command krmpfl. Did you mean...", but any non-recognized command is for some reason passed to python. I am confused.
Does anyone have an idea on how to debug this or how to move forward? I've tried type krmpfl
but this (correctly) echoes bash: type: krmpfl: not found
My setup:
- Win10 using Ubuntu 18.04 within WSL
- ConEmu as a console
- Bash-it
- Python 3.8
- Click (python package) installed to simplify creating commands
解决方案
If your current shell function defines a function named command_not_found_handle
, bash
runs that for a non-existent command rather than immediately failing with a "command not found" error. In your case, that function exists and calls /usr/lib/command-not-found
, which appears to be a Python script that tries to download (or at least suggest you download) a package with apt_pkg
, but you don't have that Python module installed, which leads to the Python exception.
推荐阅读
- java - 从独立的 Java 应用程序访问 Websphere 数据源而不指定用户名/密码
- xamarin.forms - 如何在 Xamarin.Forms ios 中实现 UnifiedNative 广告
- javascript - 如果一个正数等于它的倒数
- ajax - 提交时不会捕获模式内的事件
- javascript - Json 对象在 IE11 中未正确获取
- state - 有没有像 Svelte 3 的 Vuex 之类的东西?
- node.js - 可能很简单:MongoDB 连接到数据库,但不向其中添加项目
- python - 持久 CPLEX - 模块 cplex 没有属性 cplex
- python - Tkinter entry.get() 仅适用于每 2 次按钮点击
- java - java.lang.NoClassDefFoundError: org/apache/htrace/core/HTraceConfiguration