bash 导入错误:使用 source ~/.bashrc 时未发生名为“gdbm”的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50187767/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:54:38  来源:igfitidea点击:

ImportError: No module named 'gdbm' occuring while using source ~/.bashrc

pythonpython-3.xbash

提问by baaz.sb

Hey after making some changes in the bashrc I tried to use

嘿,在我尝试使用的 bashrc 中进行了一些更改后

source ~/.bashrc

but got the following error

但出现以下错误

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'

I tried using the install commands as mentioned in the error

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

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.

Also some solutions mentioned to use version specific commands, but still got no solution

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

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

The pip install command gave the following error

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

Please suggest a way to sort out these error.

请提出一种解决这些错误的方法。

采纳答案by werryju

Your error is occurring most likely because your .bashrc contains a typo somewhere, therefore command-not-found is being called, but command-not-found appears to have been recently broken. (You should get the same error if you type some nonsense into your terminal directly.)

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

sudo apt install python3-gdbm=3.5.1-1

worked for me.

对我来说有效。

From running

从跑步开始

dpkg -L python3-gdbm

it looked like gdbm on my computer is being installed to python3.6 for some reason, not python3.5, but my python3 version is python3.5 (and last I checked python3.6 breaks something on ubuntu 16.04).

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

The error you got when you ran

运行时遇到的错误

sudo apt-get install python3.5-gdbm

complained about a version issue, hence manually installing the version they noted worked.

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

回答by Adam Duracz

This worked for me:

这对我有用:

sudo ln -s /usr/lib/python3.6/lib-dynload/_gdbm.cpython-36m-x86_64-linux-gnu.so /usr/lib/python3.5/lib-dynload/_gdbm.cpython-35m-x86_64-linux-gnu.so

Note the 35min the the link's name.

请注意35m链接名称中的 。