Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I replace a Python installed from source with a packaged version?

As Python 3.7 was being prepared I installed Python 3.7.0b3 from source. Now 3.7 is out and I want to use the version packaged for Ubuntu. So I've done

apt-get install python3.7

but

$ which python3.7
/usr/local/bin/python3.7

$ /usr/local/bin/python3.7 --version 
Python 3.7.0b3

How does one uninstall a Python installed from source (on Ubuntu)? Or how can I replace it with the apt repo packaged version?

like image 728
Tom Viner Avatar asked Jul 14 '18 21:07

Tom Viner


2 Answers

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:

  1. Install checkinstall
  2. Use checkinstall to make a deb of your Python installation
  3. 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).

like image 194
nneonneo Avatar answered Nov 14 '22 22:11

nneonneo


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

like image 28
Mahir Islam Avatar answered Nov 14 '22 21:11

Mahir Islam