如何让Python 2.7包(Spynner)与Python 3一起工作



Spynner文档说它支持Python>=26,但是在安装过程中我得到以下错误:

(spynner) spynner$ pip3 install spynner
Requirement already satisfied (use --upgrade to upgrade): spynner in /Users/spynner/Envs/spynner/lib/python3.4/site-packages/spynner-2.19-py3.4.egg
Collecting six (from spynner)
  Using cached six-1.10.0-py2.py3-none-any.whl
Collecting beautifulsoup4 (from spynner)
  Using cached beautifulsoup4-4.5.1-py3-none-any.whl
Collecting unittest2 (from spynner)
  Using cached unittest2-1.1.0-py2.py3-none-any.whl
Collecting pyquery (from spynner)
  Using cached pyquery-1.2.13.tar.gz
Collecting autopy (from spynner)
  Using cached autopy-0.51.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/zl/dpw1svbx2qjbl549qvzq2r640000gn/T/pip-build-3rvrid_c/autopy/setup.py", line 50
        print 'Updating __init__.py'
                               ^
    SyntaxError: Missing parentheses in call to 'print'
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/zl/dpw1svbx2qjbl549qvzq2r640000gn/T/pip-build-3rvrid_c/autopy/

所以看起来其中一个包是为2.7编写的。

是否有一些Python技巧,我可以做得到这个工作与Python 3,或者我必须去和手动纠正违规代码?

欢呼

您需要更正违规代码。有一些自动化的工具可以帮助你做到这一点,比如2to3:

2to3是一个读取Python 2的Python程序。并应用一系列修复程序将其转换为有效的Python 3。x代码。标准库包含一组丰富的修复程序,可以处理几乎所有的代码。然而,支持2to3的库lib2to3是一个灵活的通用库,因此可以为2to3编写自己的修复程序。lib2to3还可以适应需要自动编辑Python代码的自定义应用程序。

最新更新