6

when I opened terminal and $ pip install -U pip setuptools, I got an error message.

Traceback (most recent call last):
  File "/usr/lib/command-not-found", line 27, in <module>
    from CommandNotFound.util import crash_guard
ModuleNotFoundError: No module named 'CommandNotFound'

I use python3.5, and its path is /usr/bin/python3.5

I tried to find CommandNotFound package but I can't find it.

How can I fix this error?

OS: Ubuntu 16.04.3 LTS

wjandrea
  • 14,504
박주현
  • 117

3 Answers3

2

Add one more answer, as I also encountered this issue and happened to solve it.
This issue happened when I installed python3.7 from source.

Check /usr/lib/command-not-found file, it is trying to find module CommandNotFound, which is NOT shipped with python3.7 but DOES with Ubuntu under directory /usr/lib/python3/dist-packages.

What we need to do is adding the directory to python import path:

  1. vi .bashrc (or .profile)
  2. add line
    export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.7/site-packages:/usr/lib/python3/dist-packages
    Pay attention that you may need to change the /usr/local/lib/python3.7/site-packages to your own directory.
  3. exit and source .bashrc (or .profile)
xuanzhui
  • 121
0

It seems you have installed a new python3 version from source, and re-link symbol-link in /usr/bin/pyton3 from python3.5(or other system python version, it's python3.5 in ubuntu16.04) to /usr/local/bin/python3(or other location you installed the new python version). I solved the problem by following steps:

  1. check the python3 symbol link using ls -la /usr/bin/python3*.
  2. if it links /usr/local/bin/python3 or other location where you installed the new python version, delete it using sudo rm -f /usr/bin/python3.
  3. re-link the python3 to system python3 version using `sudo ln -s python3.5 /usr/bin/python3', python3.5 is the system python version, you can comfirm it in step 1.

Then the error disappeared when you execute an unknow command.

xbo
  • 1
0

From the answer on "missing package CommandNotFound" by LittleByBlue:

Solution: Unlike I mentioned before my python3.5.1 installation was not removed by the update. It was still under /usr/local/bin/python3.5.

Tracing the Error: I wrote a few debug lines into /usr/lib/python3.5/_sysconfigdata.py:

print("python-version", sys.version_info)
print("python-gcc-version",sys.version)
print("python-executable",sys.executable)

The output was different between calling /usr/bin/python3 and rhythmbox, but the python-executable was in both ways /usr/bin/python3

Then I searched for the wrong installation using whereis python3 and removed /usr/local/bin/python3.5

Then I purged and reinstalled python3 and ran apt install -f. So this Error disappeared.

Remember: never install stuff from source, if it might be in the repos sometime or, at least remove it before your package manager installs it.

wjandrea
  • 14,504
Hamed
  • 820
  • 9
  • 12