command-not-found fails when user-installed python3 is in PATH
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
command-not-found |
New
|
Undecided
|
Unassigned |
Bug Description
I have a second installation of python3 (from Anaconda) and it's first in my user path:
$ which python3
/home/matt/
This seems to be causing a problem with command-not-found. When I enter an invalid command in the terminal:
$ fake_command
Failed to import the site module
Traceback (most recent call last):
File "/usr/lib/
main()
File "/usr/lib/
known_paths = addusersitepack
File "/usr/lib/
user_site = getusersitepack
File "/usr/lib/
user_base = getuserbase() # this will also set USER_BASE
File "/usr/lib/
USER_BASE = get_config_
File "/usr/lib/
return get_config_
File "/usr/lib/
_init_
File "/usr/lib/
from _sysconfigdata import build_time_vars
File "/usr/lib/
from _sysconfigdata_m import *
ImportError: No module named '_sysconfigdata_m'
I can get the expected behavior by removing the line in .bashrc that adds anaconda to the path:
$ fake_command
fake_command: command not found
The source of the problem appears to be a line in /usr/lib/
if sys.version < '3':
# We might end up being executed with Python 2 due to an old
# /etc/bash.bashrc.
import os
if "COMMAND_
Notice that it calls the command 'python3', which will resolve to the user-installed version of python3 if it's first in the path. That won't work because the anaconda installation doesn't have the modules the script needs to run. I can make the command work by being explicit about which installation of python3 to use:
$ /usr/bin/python3 /usr/lib/
fake_command: command not found
Instead of:
$ /home/matt/
Traceback (most recent call last):
File "/usr/lib/
from CommandNotFound
ImportError: No module named 'CommandNotFound'
Now, I don't know why the stack trace in the original error looks like it's coming from the system installation of python3.4, but I know that the user installation is the real wrench in the works, because the problem doesn't occur when that's not on the path. A simple solution is to make command-not-found be explicit about which installation it uses. Changing the line to:
os.execvp(
solves the problem on my system. I suppose the original intent was to use the system installation anyway, since the script relies on modules that are included with ubuntu but not in the python standard library.
This may be related to bug #1192890: /bugs.launchpad .net/ubuntu/ +source/ python3. 3/+bug/ 1192890
https:/