升级到Python3K后的第一个问题 [Python]
lvdbing@ubuntu:~/python$ spe
File "/usr/bin/spe", line 23
print 'You need to upgrade wxPython to v%s (or higher) to run SPE.'%MIN_WX_VERSION
^
SyntaxError: invalid syntax
安装了SPE启动提示print语法错误,Python 3K 是把print作为函数来调用了,所以就有这样的问题。
解决方法:
lvdbing@ubuntu:/usr/bin$ 2to3 ../share/spe/_spe/SPE.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
--- ../share/spe/_spe/SPE.py (original)
+++ ../share/spe/_spe/SPE.py (refactored)
@@ -2,7 +2,7 @@
import sys
if sys.platform.startswith('win') and sys.executable.lower().endswith('pythonw.exe'):
- from cStringIO import StringIO
使用官方自带的自动转换工具: 2to3
像上面输出的只是输出的转换前要转换的地方,正在转换要加 -w 参数。
lvdbing@ubuntu:/usr/bin$ 2to3 -w ../share/spe/_spe/SPE.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
--- ../share/spe/_spe/SPE.py (original)
+++ ../share/spe/_spe/SPE.py (refactored)
@@ -2,7 +2,7 @@
import sys
if sys.platform.startswith('win') and sys.executable.lower().endswith('pythonw.exe'):
- from cStringIO import StringIO
+ from io import StringIO
虽然这个spe没语法错误了,但是它依赖的其他模块也要跟着一起转换才能被新的Python3.0解析器解析到。