My python installation is broken/corrupted. How do I fix it?
Asked Answered
C

4

7

I followed these instructions on my RedHat Linux version 7 server (which originally just had Python 2.6.x installed):

beginning of instructions

install build tools

sudo yum install make automake gcc gcc-c++ kernel-devel git-core -y

install python 2.7 and change default python symlink

sudo yum install python27-devel -y
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python2.7 /usr/bin/python

yum still needs 2.6, so write it in and backup script

sudo cp /usr/bin/yum /usr/bin/_yum_before_27
sudo sed -i s/python/python2.6/g /usr/bin/yum
sudo sed -i s/python2.6/python2.6/g /usr/bin/yum

should display now 2.7.5 or later:

python -V 

end of instructions

The above commands and comments were taken from:

http://www.lecloud.net/post/61401763496/install-update-to-python-2-7-and-latest-pip-on

The python -v command returned this:

-bash: python: command not found

Now it is as if I have no Python installed. I don't want yum to break. I tried installing Python 3.4.

whereis python shows this:

python: /usr/bin/python2.6 /usr/bin/python2.6-config /usr/bin/python /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python2.7 /usr/local/bin/python3.4m-config /usr/local/bin/python2.7-config /usr/local/bin/python3.4 /usr/local/bin/python3.4m /usr/local/lib/python2.7 /usr/local/lib/python3.4 /usr/include/python2.6 /usr/share/man/man1/python.1.gz

What should I do now? I want a working installation of Python. For certain things I'm doing, I need it to be 2.7 or higher. I want yum to still work.

Cameleer answered 8/3, 2015 at 0:21 Comment(2)
Why didn't you just install the python27 package and leave it at that?Trituration
It didn't seem to be working. I followed some instructions I found online for doing it. But my results from python -V showed 2.6.x was still installed.Cameleer
C
4

Do

sudo update-alternatives --remove-all python
sudo ln -sf /usr/bin/python2.7 /usr/bin/python
Castaway answered 19/6, 2015 at 13:7 Comment(2)
I don't know how but this worked for me ! I "accidentally" removed some .so files and this fixed it.Cravat
Thats removing all broken links to python, then adding a new soft link that "translates" the install name python2.7 where it was installed, to the pretty name python you are used to running in your excecution pathCastaway
D
2

I got the same issue while upgrading ubuntu 18 to 19, this made it:

sudo rm /usr/bin/python
sudo ln -s /usr/bin/python2.7 /usr/bin/python
do-release-upgrade

From:

https://bugs.launchpad.net/ubuntu/+source/ubuntu-release-upgrader/+bug/1825655

Dig answered 21/4, 2019 at 7:28 Comment(0)
N
1

For me, nothing worked except this one:

unlink /usr/bin/python3
ln -s /usr/bin/python3.7 /usr/bin/python3

Credit: https://josephgeis.dev/2020/04/upgrading-to-ubuntu-20-04-python3/

Nielsen answered 3/10, 2020 at 22:48 Comment(0)
T
0

This is easily fixed by installing the python27 package via yum. It should install in /usr/bin, and may overwrite the /usr/bin/python symlink that should be pointing to 2.6. If it did (just run ls -l python* in /usr/bin to see), remove the symlink and point it back to 2.6. Next create a symlink for /usr/local/bin/python pointing at /usr/bin/python2.7. Finally, modify your ~/.bashrc or ~/.bash_profile (whichever you use) to have /usr/local/bin before /usr/bin in your PATH:

export PATH=/usr/local/bin:$PATH

at the very end of the file. This way, /usr/bin/python remains linked to Python 2.6, which is what the system expects, and when you run python at the command line it'll start up 2.7. You shouldn't have to make any changes to the yum script either - just blanket replacing python with python2.6 without understanding what you're doing is not a very good idea.

I'd also recommend installing Python 3.4 in /usr/local/bin if possible, where the binary will be named python3 by convention. Even if it installs in /usr/bin, you'll still have the choice of running python3 or python3.4 to specify which version you want. I work on a CentOS system that has each version of Python from 2.4 up to 3.4 installed, all in /usr/local/bin (I'm sure this was done manually, and not via yum), while the only python* in /usr/bin is 2.6. I couldn't find a python3 package for RedHat (I may not have been looking hard enough), so I'd recommend building the latest version from source (3.4.3 as of this writing). Unzip the tarball in a suitable directory, check out the README file, then, in the Python-3.4.3 directory, run ./configure --help to see what the options are, and if you need to change anything. As long as you have gcc installed, and don't need to link to any weird math libraries or anything, you should just be able to run:

./configure
make
make test
sudo make install

and it'll install to /usr/local/bin. Check the messages at the end of the make step, as it'll list any modules it wasn't able to build there. Fails usually happen because you don't have a required library installed, so look in setup.py in the base directory in the detect_modules() function (starting on line 449, and stretching all the way down to line 1564). Install both the lib and the -devel packages so you get the necessary headers.

This same process can also be followed if you want to install the latest 2.7.9, instead of RH's 2.7.5. One of the major (in my eyes) advantages of 2.7.9 is that pip is installed by default, making third-party module installation that much easier.

Good luck!

Trituration answered 8/3, 2015 at 4:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.