LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Password
Fedora This forum is for the discussion of the Fedora Project.

Notices

Reply
 
Search this Thread
Old 07-31-2012, 09:31 AM   #1
hpfeil
Member
 
Registered: Nov 2010
Location: Tucson, Arizona US
Distribution: Slackware Current, custom kernel, amd64, Beyond LinuxFromScratch
Posts: 130
Blog Entries: 1

Rep: Reputation: Disabled
Lightbulb Python3.2 vs yum


[Fedora 17, X86_64]

Just for fun, not happy with two versions of python on the same machine (python2, python3), I thought I'd change the /usr/bin/python link to point to python3.2. No worries until invoking `yum update` the next day in response to some security notices over at US-CERT.
File "/bin/yum", line 30
except KeyboardInterrupt, e:
^ ( the arrow points to the comma )
SyntaxError: invalid syntax

Strange, thought I. [Skip all of the boring failed attempts to solve the problem.]
When I restored /usr/bin/python to point to python2.7, yum worked again as advertised.
Problem solved. Just thought I'd document that in case someone else breaks yum by upgrading python. Perhaps a heads-up to the yum chaps for future reference, the current version of yum breaks with python3.2?

Last edited by hpfeil; 07-31-2012 at 09:33 AM. Reason: significant spaces were automatically removed
 
Old 07-31-2012, 10:38 AM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Philly, PA
Distribution: Kubuntu x64, RHEL, Fedora Core, FreeBSD, Windows x64
Posts: 1,458
Blog Entries: 35

Rep: Reputation: 363Reputation: 363Reputation: 363Reputation: 363
Perhaps you should configure it using alternatives and see if you still have a problem with yum.

Code:
alternatives --install /usr/bin/python python /usr/bin/python2.7 20000
alternatives --install /usr/bin/python python /usr/bin/python3.2 20000
alternatives --test --config python
alternatives --config python

Last edited by sag47; 07-31-2012 at 10:39 AM.
 
Old 08-01-2012, 10:00 AM   #3
hpfeil
Member
 
Registered: Nov 2010
Location: Tucson, Arizona US
Distribution: Slackware Current, custom kernel, amd64, Beyond LinuxFromScratch
Posts: 130
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Fixer in /usr/bin/python3-2to3 sez:

except
Converts except X, T to except X as T.

- except KeyboardInterrupt, e:
- print >> sys.stderr, "\n\nExiting on user cancel."

+ except KeyboardInterrupt as e:
+ print("\n\nExiting on user cancel.", file=sys.stderr)

Tools used:
cp /usr/bin/yum .
/usr/bin/python3-2to3 -w yum
diff yum.bak yum

I imagine there are a lot of python programers who need to study http://docs.python.org/py3k/library/2to3.html
The 2to3 tool makes the transition easy. Just run it against your existing code.
 
Old 08-01-2012, 10:26 AM   #4
hpfeil
Member
 
Registered: Nov 2010
Location: Tucson, Arizona US
Distribution: Slackware Current, custom kernel, amd64, Beyond LinuxFromScratch
Posts: 130
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
BTW, there were other things that needed fixing, but I posted only the bit that appeared onscreen from bash's STDERR.
Here's the full diff:

--- yum (original)
+++ yum (refactored)
@@ -3,7 +3,7 @@
try:
import yum
except ImportError:
- print >> sys.stderr, """\
+ print("""\
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

@@ -20,13 +20,13 @@
the yum faq at:
http://yum.baseurl.org/wiki/Faq

-""" % (sys.exc_value, sys.version)
+""" % (sys.exc_info()[1], sys.version), file=sys.stderr)
sys.exit(1)

sys.path.insert(0, '/usr/share/yum-cli')
try:
import yummain
yummain.user_main(sys.argv[1:], exit_code=True)
-except KeyboardInterrupt, e:
- print >> sys.stderr, "\n\nExiting on user cancel."
+except KeyboardInterrupt as e:
+ print("\n\nExiting on user cancel.", file=sys.stderr)
sys.exit(1)
 
Old 08-01-2012, 10:51 AM   #5
sag47
Senior Member
 
Registered: Sep 2009
Location: Philly, PA
Distribution: Kubuntu x64, RHEL, Fedora Core, FreeBSD, Windows x64
Posts: 1,458
Blog Entries: 35

Rep: Reputation: 363Reputation: 363Reputation: 363Reputation: 363
Then simply change the interpreter in the first line of yum. I didn't realize yum was written in Python.

Code:
# vim $(which yum)

 - #!/usr/bin/python
 + #!/usr/bin/python2
It's better than attempting to convert yum to Python 3 which would be a mistake in my opinion.

Also please make use of code markup for example
Code:
[code]# vim $(which yum)

 - #!/usr/bin/python
 + #!/usr/bin/python2[/code]
Your posts would be much easier to read.

Last edited by sag47; 08-01-2012 at 11:00 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to run bpython with python3? saavedra29 Slackware 2 03-08-2012 07:36 PM
yum install flash ... yum: command not found ... which yum ... /usr/bin/yum tg3793 Fedora 8 04-13-2011 11:25 AM
[SOLVED] python3 - trying to pickle object raises TypeError comp_brad1136 Programming 2 04-06-2011 07:37 AM
how to update rhel 5 using centos yum updater without conflict with yum redhat plugin udayvikram Linux - Newbie 1 03-29-2010 12:56 PM
problem after yum yum yum (delicious) alaios Fedora 3 01-14-2009 02:34 AM


All times are GMT -5. The time now is 07:48 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration