ImportError:使用source~/.bashrc时没有出现名为'gdbm'的模块

baa*_*.sb 5 python bash python-3.x

嘿我在尝试使用的bashrc中做了一些更改

source ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

但得到以下错误

baaz@FireStorm:~$ source ~/.bashrc
Traceback (most recent call last):
  File "/usr/lib/python3.5/dbm/gnu.py", line 4, in <module>
    from _gdbm import *
ImportError: No module named '_gdbm'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 7, in <module>
    import dbm.gnu as gdbm
  File "/usr/lib/python3.5/dbm/gnu.py", line 6, in <module>
    raise ImportError(str(msg) + ', please install the python3-gdbm package')
ImportError: No module named '_gdbm', please install the python3-gdbm package

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/command-not-found", line 27, in <module>
    from CommandNotFound.util import crash_guard
  File "/usr/lib/python3/dist-packages/CommandNotFound/__init__.py", line 3, in <module>
    from CommandNotFound.CommandNotFound import CommandNotFound
  File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 9, in <module>
    import gdbm
ImportError: No module named 'gdbm'
Run Code Online (Sandbox Code Playgroud)

我尝试使用错误中提到的安装命令

baaz@FireStorm:~$ sudo apt-get install python3-gdbm
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-gdbm is already the newest version (3.6.5-3~16.04.york0.2).
python3-gdbm set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Run Code Online (Sandbox Code Playgroud)

还提到了一些使用版本特定命令的解决方案,但仍然没有解决方案

baaz@FireStorm:~$ sudo apt-get install python3.5-gdbm
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package python3.5-gdbm is a virtual package provided by:
  python3-gdbm 3.5.1-1 [Not candidate version]

E: Package 'python3.5-gdbm' has no installation candidate
Run Code Online (Sandbox Code Playgroud)

pip install命令给出了以下错误

baaz@FireStorm:~$ sudo pip3 install gdbm --upgrade
The directory '/home/baaz/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/baaz/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting gdbm
  Could not find a version that satisfies the requirement gdbm (from versions: )
No matching distribution found for gdbm
Run Code Online (Sandbox Code Playgroud)

请建议一种解决这些错误的方法.

小智 5

您的错误很可能是因为您的 .bashrc 在某处包含拼写错误,因此正在调用 command-not-found,但 command-not-found 最近似乎已被破坏。(如果你直接在终端中输入一些废话,你应该得到同样的错误。)

sudo apt install python3-gdbm=3.5.1-1
Run Code Online (Sandbox Code Playgroud)

为我工作。

从跑步开始

dpkg -L python3-gdbm
Run Code Online (Sandbox Code Playgroud)

看起来我电脑上的 gdbm 出于某种原因安装到了 python3.6,而不是 python3.5,但我的 python3 版本是 python3.5(最后我检查了 python3.6 在 ubuntu 16.04 上有问题)。

运行时遇到的错误

sudo apt-get install python3.5-gdbm
Run Code Online (Sandbox Code Playgroud)

抱怨版本问题,因此手动安装他们指出有效的版本。