问题
我刚刚在我的Ubuntu上安装了python 3.5.1,但是得到了这个错误信息,无论我用Anaconda还是用apt-get安装:
复制代码
No module named ‘gdbm’
我还尝试使用以下方法安装gdbm :
复制代码
sudo apt-get install gdbm
但是不能解决这个问题。
回答1
在我的情况下,如果我尝试运行任何在bash shell中不存在的命令,我会得到这个错误:
复制代码
$ programthatdoesntexist
Traceback (most recent call last):
File"/usr/lib/python3.5/dbm/gnu.py", line 4, in
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
import dbm.gnu as gdbm
File"/usr/lib/python3.5/dbm/gnu.py", line 6, in
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
from CommandNotFound.util import crash_guard
File"/usr/lib/python3/dist-packages/CommandNotFound/init.py", line 3, in
from CommandNotFound.CommandNotFound import CommandNotFound
File"/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 9, in
import gdbm
ImportError: No module named ‘gdbm’
我已经从仓库安装了python3.6, ppa.launchpad.net/jonathonf/python-3.6/ubuntu
当绑定到重新安装软件包时,command-not-found python3-commandnotfound python3-gdbm python3-gdbm-dbg sessioninstaller ,我注意到apt正在从这里拉取源代码:
复制代码
Get:1 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial/main amd64 python3-gdbm amd64 3.6.5-3~16.04.york0.2 [14.6 kB]
为了解决这个问题,我删除了那个存储库:
复制代码
sed -i ’ s/^/#/’ /etc/apt/sources.list.d/jonathonf-ubuntu-python-3_6-xenial.list
然后重新运行此命令(以root身份):
复制代码
apt update ; apt purge python3-gdbm ; apt install command-not-found python3-commandnotfound python3-gdbm python3-gdbm-dbg sessioninstaller
现在一切又正常了
复制代码
$ lol
No command ‘lol’ found, did you mean:
Command ‘sol’ from package ‘aisleriot’ (main)
Command ‘col’ from package ‘bsdmainutils’ (main)
lol: command not found
回答2
你是否尝试安装软件包python3-gdbm
代码复制成功
sudo apt-get install python3-gdbm
回答3
复制代码
sudo apt-get install python3.6-gdbm
此命令为我工作
回答4
我遇到了同样的问题,并通过以下方法解决了问题:
复制代码
sudo apt install python3-gdbm=3.5.1-1
dpkg -L python3-gdbm
现在我得到了同样的问题。
所以,在最新版本的python3-gdbm中显然存在错误(bug)。