It seems that your Python built from source is under /usr/local
, and your PATH
variable has /usr/local/bin
before /usr/bin
, since running python3.7
gets you the one under /usr/local
rather than the packaged one which would be /usr/bin/python3.7
.
Look at your PATH
to verify this.
echo $PATH
(When you run a program in bash
, that particular running bash
instance will remember the location and not rescan the directories in the PATH
for that program again, so it will not notice a new file that has appeared somewhere earlier in the PATH
. You can prevent this by running hash -r
to reset the cache or by just exiting the shell and launching it again.)
I presume your goal is for python3.7
(or any of the other commands provided by Python) to run the versions from your packaged install in /usr
.
Unfortunately the python build process does not provide an uninstall method -- the only automated way to remove just the files installed by a source Python install requires using other tools ahead of time (such as checkinstall
).
So you have some choices :
Change your PATH
so that /usr/local/bin
is after /usr/bin
. To do this, edit your ~/.profile
file or whatever other script you have configuring your PATH
and logout/login. This will also affect any other commands you run that are available in both /usr/local/bin
and /usr/bin
.
Remove /usr/local
and reinstall anything else you want there. If a Python install is the only thing in your /usr/local
, or if you can easily reinstall anything else you had there, this might be the way to go.
Painstakingly figure out what files under /usr/local/bin
were part of Python and remove them. You might be able use the corresponding files in /usr/bin
from your installed python3
packages as a starting point to figure out the similar names for /usr/local/bin
.
One-liner to get the list of files in /usr/bin
from installed python3*
packages:
$ for pkg in $(dpkg -l 'python3*' | grep '^ii' | cut -f 3 -d' '); do dpkg -L $pkg | grep '^/usr/bin/'; done | sort
This should produce a list of files like:
/usr/bin/2to3-3.x
/usr/bin/chardet3
...
(I've tested this one-liner on Debian, I'm not sure if any changes are required for Ubuntu)