Python Forum
Update Python 2.7 in place
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Update Python 2.7 in place
#1
A linux system has /usr/local/bin/python2.7 installed with a time stamp from August 2014. "python2.7 --version" says just "Python 2.7". There are many packages installed in /usr/local/lib/python2.7/site-packages.

Is there a way to update this in place to 2.7.14 that will not break the existing installed site-packages? (Searched for the answer but if it was there it was well and truly buried under all the threads about migrating 2.7.x to 3.x.)

Note, previously asked (but not answered) here: https://stackoverflow.com/questions/4821...7-in-place
Reply
#2
Is there no python in /usr/bin/python ? Can you say more about the linux system and why you want to update the system's python.
Reply
#3
Use pyenv,my tutorial.
It's make really simple to change versions,
and safe to don't mess at all with default OS Python versions.
mint@mint ~ $ pyenv install 2.7.14
Downloading Python-2.7.14.tar.xz...
-> https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz
Installing Python-2.7.14...
Installed Python-2.7.14 to /home/mint/.pyenv/versions/2.7.14

# Make it default version,set both python and pip from command line to 2.7.14
mint@mint ~ $ pyenv global 2.7.14
So what you should use is Python 3.6.
Downloading Python-3.6.4.tar.xz...
-> https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
Installing Python-3.6.4...
Installed Python-3.6.4 to /home/mint/.pyenv/versions/3.6.4

# Make it default version,set both python and pip from command line to 3.6.4
mint@mint ~ $ pyenv global 3.6.4
Going back to OS default Python is simple to.
mint@mint ~ $ pyenv local system
mint@mint ~ $ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
mint@mint ~ $ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Reply
#4
(Jan-22-2018, 06:39 PM)Gribouillis Wrote: Is there no python in /usr/bin/python ? Can you say more about the linux system and why you want to update the system's python.

This is Centos 6.9 and the system provided python is 2.6. There were too many pieces of python based software that wouldn't run with that so 2.7 (a very early 2.7) was installed in /usr/local. Now a couple of years later there are a lot of site-packages installed in that 2.7. I recently ran into a piece of python software which blew up in a mysterious manner running with this old 2.7, but worked with 2.7.14 on another system. Although that issue eventually turned out to be due to having an older version of NumPy installed, it raised the question of how to update 2.7 itself, in place. As opposed to installing yet another version (2.7.14) and then installing all of the may site-packages into it. Updating the site-packages is relatively easy, but I have yet to see a supported method for updating the underlying Python 2.7.
Reply
#5
(Jan-22-2018, 08:32 PM)mathog Wrote: but I have yet to see a supported method for updating the underlying Python 2.7.
No need to update underlying python.
pyenv work for CentOS example.

I understand your explanation,but it make no sense to try to fix that way.
pyenv or the new pipenv is great,and also virtual environment(now also build into 3.6),
should make it easy to avoid conflict you describe.
You just need to look at train using these tools.
Reply
#6
I don't know a supported method to update python in place. Such methods must exist because linux package managers update python and preserve installed python modules, but I don't know them.

If you need to reinstall, perhaps using Snippsat's suggestion, you can first list all your installed modules by running

Output:
/usr/local/bin/python2.7 -c "import pkgutil; print([(t[1], t[0].path) for t in pkgutil.iter_modules()])"
You could use a script running pip to reinstall most of them automatically.
Reply
#7
If you want to try here is a link How to install the latest version of Python on CentOS
Just to make it clear,so is this not necessary at all using tool posted over.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020