Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

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.

like image 727
baaz.sb Avatar asked May 05 '18 09:05

baaz.sb


2 Answers

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.)

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).

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.

like image 166
werryju Avatar answered Oct 10 '22 15:10

werryju


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 35m in the the link's name.

like image 27
Adam Duracz Avatar answered Oct 10 '22 15:10

Adam Duracz