How do I replace a Python installed from source with a packaged version?
Since you opened a bounty, I can't vote to close as a duplicate, but this question would seem to provide a possible solution. Quoting from the accepted answer:
You can use checkinstall to remove Python. The idea is:
- Install checkinstall
- Use checkinstall to make a deb of your Python installation
- Use
dpkg -r
to remove the deb.
checkinstall
basically wraps a make install
command and creates a Debian .deb
package based on what was installed. Then, you can just uninstall that package to reverse make install
completely. To be perfectly safe you may want to uninstall the packaged Python 3.7 first and reinstall it afterwards to avoid any conflicts (I wouldn't expect any, though, since the packaged version lives in /usr while your source version lives in /usr/local).
If you don't have your source files around anymore, you can always download them again (https://www.python.org/downloads/release/python-370b3/) and rebuild Python. Specifically, the checkinstall
commands would look something like this:
sudo apt install checkinstall
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0b3.tgz
tar xf Python-3.7.0b3.tgz
cd Python-3.7.0b3
./configure && make
sudo checkinstall -D --fstrans=no make install
sudo dpkg -r Python-3.7.0b3.deb
(-D
creates a Debian package, --fstrans=no
disables use of a temporary directory for installation).
Since I was also moving to python 3.7, I came across this question and decided to answer it, as well as finish my installation. This are the two sources, which I used for installing python 3.7 on ubuntu 16.04: https://askubuntu.com/questions/865554/how-do-i-install-python-3-6-using-apt-get https://superuser.com/questions/241865/updating-python-on-ubuntu-system
Apparently from the first source the deadsnakes PPA contain Python 3.7 - Link: https://github.com/deadsnakes/python3.7/tree/ubuntu/xenial/Python
So following from my first source, I used the following commands to install Python 3.7:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.7
It installed Python 3.7 successfully but my Python 3.5.2 remains default. You can invoke/use Python 3.7 by running the commands:
python3.7 script.py
It works, so I decided to set Python 3.7 as default by removing python 3.5, but I came across my second source, and just decided to stick with using python3.7
, when running my script in the terminal.
Apparently it says: Ubuntu policies extensively for writing end-user software. So basically, a large part of the system is written in Python. To switch to Python 3.7, there needs to be done a piece of work consisting of updating and re-testing all the scripts.
So to say you can't just switch to Python 3.7 and delete the older version.
Also from a comment from my first source it states deleting the older version might break the system. I haven't been around to deleting my older version in case it might break the system, but since you are asking for how to download Python 3.7, I think my first source and the first part of my answer should to the work.
I hope it helps :)
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 yourPATH
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 installedpython3
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)