问题
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.
回答1:
Do
sudo update-alternatives --remove-all python
sudo ln -sf /usr/bin/python2.7 /usr/bin/python
回答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
回答3:
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!
来源:https://stackoverflow.com/questions/28921697/my-python-installation-is-broken-corrupted-how-do-i-fix-it