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

时间:2018-05-05 09:17:59

标签: python python-3.x bash

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

source ~/.bashrc

但出现以下错误

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'

我尝试使用错误

中提到的安装命令
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.

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

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

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

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

2 个答案:

答案 0 :(得分:4)

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

sudo apt install python3-gdbm=3.5.1-1

为我工作。

从跑步

dpkg -L python3-gdbm
看起来我的计算机上的gdbm由于某种原因被安装到python3.6,而不是python3.5,但是我的python3版本是python3.5(最后我检查了python3.6在ubuntu 16.04上打破了一些东西)。 / p>

运行时出现的错误

sudo apt-get install python3.5-gdbm

抱怨版本问题,因此手动安装他们注意到的版本。

答案 1 :(得分:2)

这对我有用:

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

请注意链接名称中的35m