Yum crashed with Keyboard Interrupt error
Asked Answered
R

7

98

I installed the newer version of python (3.2.3) than the one available in Fedora16 (python2.7)

And now yum stops working. It shows the following error.

[root@localhost yum-3.4.3]# yum
  File "/usr/bin/yum", line 30
   except KeyboardInterrupt, e:
                           ^
SyntaxError: invalid syntax

Please advice as how to resolve the error. It would be helpful as I am not able to update or install any package.

Refinement answered 26/6, 2012 at 18:16 Comment(2)
Don't replace the system python on a Fedora machine. You should have installed python3 as something like /usr/local/bin/python3.Illustrious
In 2019, with python2 all but deprecated, one should not have to worry about linking a python3 executable to /usr/bin/python. It is incredibly lazy for a package to have this issue when the fix is literally to add a single character to your python2 files (ie #!/usr/bin/python2 vs #!/usr/bin/python)Mozellemozes
O
146

Because yum does not support Python3.
You can run command vi /usr/bin/yum, change /usr/bin/python to /usr/bin/python2 in first line.
Thus you can run the command yum by Python2 instead of Python3.

Note however that this will make your setup unsupported and thus unmaintainable (as does what you did). You will likely have other similar problems in the future with other system packages.
If you want to use an alternative Python installation, consider installing it into /usr/local, /opt or using pyenv.

Orthocephalic answered 9/5, 2015 at 6:56 Comment(1)
For AWS Linux 2 AMI users: if you also get a OSError even updating /usr/bin/yum make sure start of file : /usr/libexec/urlgrabber-ext-down is also edited to python2Tenebrous
P
64

This issue happens when user upgrades to python3, Just simply edit the file --> /usr/bin/yum and change to first line to --> "#!/usr/bin/python2"

The above solution wouldn't solve the all yum dependency problems, its better to run the below commands.

sudo ln -s /usr/local/bin/python3 /usr/bin/python3 (Mark latest python as python3)

sudo ln -sf /usr/bin/python2.7 /usr/bin/python (nake 2.7 as default python)

THanks, Daman

Perichondrium answered 2/1, 2018 at 3:1 Comment(4)
I tried all solutions, yours was the one to solve the problem.Xenogamy
Yes, you are the one who solved the problem. Good finding. ThanksCavit
Yes I confirm Thanks.Elboa
yes, changing the #!/usr/bin/python just lead to more downstream issues in yum commands. This is much more livable.Susannasusannah
H
26

I'm guessing you installed Python 3.2.3 from source and used "make install" as the last command. That command has the unfortunate side-effect of replacing the system installed version command "python" with the new version. Using "make altinstall" doesn't replace "python".

The command "python" is just a symbolic link to "python2", which in turn is a symbolic link to "python2.7". You should be able to restore "python" by executing the following command:

cd /usr/bin
sudo ln -s python2 python
Hypothyroidism answered 27/6, 2012 at 6:4 Comment(4)
I managed to do a little bit different : sudo ln -s python2.6 pythonArtieartifact
in 2019, with python2 all but deprecated, one should not have to worry about linking a python3 executable to /usr/bin/python. It is incredibly lazy for a package to have this issue when the fix is literally to add a single character to your python2 files (ie #!/usr/bin/python2 vs #!/usr/bin/python)Mozellemozes
@Mozellemozes the OP mentioned that this is in Fedora 16 which is EOL since 02.2013.Denunciatory
Got an error: ln: failed to create symbolic link ‘python’: File exists. I have to use sudo ln -fs /usr/bin/python2 /usr/bin/python to make it work.Hack
B
11

Thanks Damanvir! Changing the line in /usr/bin/yum worked!

This is a little off topic and might be removed but it might help someone.

These are the steps I used to install Python 3.7 on Centos and fix the yum error.

Download from https://www.python.org/

tar -xvf
./configure --enable-optimizations

make
make install

OR

make altinstall

make altinstall is used to prevent replacing the default python binary file /usr/bin/python.

cd /usr/bin

Remove the current symbolic link to the previous version

rm python

OUTPUT: rm: remove symbolic link ‘python’? y

Find the location of the new version

whereis python3.7
 OUTPUT: python3: /usr/local/bin/python3.7

Verify this is correct

  /usr/local/bin/python3.7 --version
  OUTPUT: Python 3.7.0

Create a symbolic link to the location of the new version

ln -s /usr/local/bin/python3.7 python

python --version

OUTPUT: Python 3.7.0

Yum commands will show the following error:

  File "/bin/yum", line 30
      except KeyboardInterrupt, e:

  SyntaxError: invalid syntax

Change the top line of this file from using python to python2

  vi /usr/bin/yum 
    #!/usr/bin/python2

Reference: https://tecadmin.net/install-python-3-7-on-centos/

Brandtr answered 20/10, 2018 at 17:41 Comment(0)
S
6

The real answer - to ensure that you are back on a supportable version of python (in the event you are looking at this for an issue with RHEL 7).

cd /usr/bin
sudo unlink python
sudo ln -s python2 python
Soap answered 29/7, 2020 at 12:44 Comment(0)
A
3

Your yum looks for python2. Let's use 'alternatives' to switch between pythons2 and python3.

  • run --> sudo alternatives --config python
  • Enter to keep the current selection[+], or type selection number:

If you don't configure it. How to do that?

  • sudo alternatives --install /usr/bin/python python /usr/local/bin/python3.8 60

  • sudo alternatives --install /usr/bin/python python /usr/bin/python2 50

Allodium answered 27/7, 2021 at 2:48 Comment(0)
R
0

It's only a binary link issue. You can copy the working /usr/bin/python2 from any system and copy to current system location /usr/bin/python2

#cd /usr/bin

#ln -s python2 python
Roughspoken answered 10/4, 2021 at 5:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.