48

I just finished installing python 3.5.1 on my Ubuntu, but am faced with this error message, regardless if I'm installing with Anaconda or with apt-get:

No module named 'gdbm'

that normally displays on my terminal. I have also tried installing gdbm using:

sudo apt-get install gdbm

but doesn't solve the problem. Can I get a help on how to fix this problem from anyone here?

Seanny123
  • 279
  • 1
  • 6
  • 16

12 Answers12

61
sudo apt-get install python3.5-gdbm

helped me

Klesun
  • 701
34

In my case, if I tried running any command that doesn't exist in a bash shell I would get this gross error:

$ programthatdoesntexist
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'

None of the answers above worked in my case. Although this problem has been solved, this might help someone. If you are still having this issue, maybe this will help:

I had installed python3.6 from the repository ppa.launchpad.net/jonathonf/python-3.6/ubuntu , and apparently that broke some things.

When tying to reinstall the packages command-not-found python3-commandnotfound python3-gdbm python3-gdbm-dbg sessioninstaller, I noticed that apt was pulling sources from here:

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]

To fix the issue, I simply removed that repository:

sed -i ' s/^/#/' /etc/apt/sources.list.d/jonathonf-ubuntu-python-3_6-xenial.list

And than re-ran this command (as root):

apt update ; apt purge python3-gdbm ; apt install command-not-found python3-commandnotfound python3-gdbm python3-gdbm-dbg sessioninstaller

Now, everything works again:

$ lol
No command 'lol' found, did you mean:
 Command 'sol' from package 'aisleriot' (main)
 Command 'col' from package 'bsdmainutils' (main)
lol: command not found
Chev_603
  • 1,676
  • 3
  • 18
  • 30
  • 3
    I just had the same on 16.04 LTS. I think looking at the timing of your answer a new update either in the jonathonf repo or standard repos has a conflict. Since I moved to pyenv for my Python versions anyway, getting rid of the jonathonf repository is probably a good idea for me. – Phil May 10 '18 at 08:37
  • Thanks. Just a note that people might also notice the crash report app firing because command-not-found is failing. – jamesc May 12 '18 at 16:49
  • 2
    Had the same problem, and this solution worked. At the same time, python3.6 -m venv was broken for me. Changing to the deadsnakes repository solved all my issues. See also https://stackoverflow.com/a/50197283/7599943 – Jonas Dahlbæk May 15 '18 at 10:23
  • sudo ppa-purge ppa:jonathonf/python-3.6 fixed it for me (it reinstalled the necessary packages automatically). – jfs May 16 '18 at 11:28
9

Have you tried installing the package python3-gdbm

sudo apt-get install python3-gdbm
squareborg
  • 10,517
8

Depending on version of python you recently installed, ONE of the following:

sudo apt-get install python3.5-gdbm
sudo apt-get install python3.6-gdbm
sudo apt-get install python3.7-gdbm
6

I have python 3.6 install and working i have tried many things but

sudo apt-get install python3.6-gdbm

This command worked for me

2

I had the same issue and got it solved by:

sudo apt install python3-gdbm=3.5.1-1
dpkg -L python3-gdbm

running synaptic, for something else, displayed that python3-gdbm needed an update. I allowed synaptic to make the update and: Now I get the same issue back.

When running above commands again I get as message, in the terminal, for the first command: The following packages will be DOWNGRADED : python3-gdbm. After answering Y to the question if I want to continue, traceback works again.

So there is clearly something wrong (bug) in the latest version of python3-gdbm.

muru
  • 197,895
  • 55
  • 485
  • 740
defossez
  • 161
1
sudo apt install python3-django

helped me

zxdc
  • 11
  • 4
    Hi zxdc, you might want to explain your answer. Does installing django also install gdbm somehow? – Hee Jin May 08 '18 at 15:37
0

I had this error when I had forgot to activate a Python virtual environment that was used with the command I was trying to run (The tx command in my case).

Orienteerix
  • 103
  • 6
0

The correct answer is to install the python-gdbm package for your version of python. In the error trace if you see python3.8 then you need to run sudo apt-get install python3.8-gdbm and so on.

Zanna
  • 70,465
Anon
  • 1
0
$ whatever
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'

remove gdbm first

apt remove --purge python3-gdbm

install again

apt install python3-gdbm

its work for me

0

use this command to show which python3-gdbm has been installed:

apt search gdbm | grep python

if there is python-gdbm installed which is not matched with the python3, such as python3.6-gdbm. You can use this command to remove this missing matched one:

sudo apt autoremove python3.6-gdbm
-2

sudo apt-get install python3.6-gdbm

this command worked for me finally

step 1

step2