Python 3.x 导入错误SyntaxError
Python 3.x import error SyntaxError
我正在使用 macOS Sierra。导入 builtwith
时出现以下错误:
Daniels-MacBook-Pro:~ Daniel$ python
Python 3.5.2 |Anaconda 4.2.0 (x86_64)| (default, Jul 2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import builtwith
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/danielotero/anaconda3/lib/python3.5/site-packages/builtwith/__init__.py", line 43
except Exception, e:
^
SyntaxError: invalid syntax
如何才能正确导入它?
根据module's issue tracker,它不兼容Python 3.项目所有者说
This module was built with Python 2 in mind. Patches are welcome to also support Python 3, however would need to maintain backwards compatibility.
由于他们似乎不想将其移植到 Python 3 以保持向后兼容,您应该使用 Python 2,寻找另一个库,或尝试移植它自己。
这是因为您安装的builtwith
包是由Python2开发的,而不是Python3开发的。所以它像 Python2 一样使用 print
和 Exception
。它还使用 urllib2 库,该库在 Python3.
中分为 urllib 库的两个部分
最好用Python2(Python2.7)来完成工作,否则你必须修改builtwith
的源代码,即将所有print
语句改为print()
函数,把except Exception, e
改成except Exception as e
,把所有urllib2
函数改成urllib.requests
和urllib.error
中的函数。
我正在使用 macOS Sierra。导入 builtwith
时出现以下错误:
Daniels-MacBook-Pro:~ Daniel$ python
Python 3.5.2 |Anaconda 4.2.0 (x86_64)| (default, Jul 2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import builtwith
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/danielotero/anaconda3/lib/python3.5/site-packages/builtwith/__init__.py", line 43
except Exception, e:
^
SyntaxError: invalid syntax
如何才能正确导入它?
根据module's issue tracker,它不兼容Python 3.项目所有者说
This module was built with Python 2 in mind. Patches are welcome to also support Python 3, however would need to maintain backwards compatibility.
由于他们似乎不想将其移植到 Python 3 以保持向后兼容,您应该使用 Python 2,寻找另一个库,或尝试移植它自己。
这是因为您安装的builtwith
包是由Python2开发的,而不是Python3开发的。所以它像 Python2 一样使用 print
和 Exception
。它还使用 urllib2 库,该库在 Python3.
中分为 urllib 库的两个部分
最好用Python2(Python2.7)来完成工作,否则你必须修改builtwith
的源代码,即将所有print
语句改为print()
函数,把except Exception, e
改成except Exception as e
,把所有urllib2
函数改成urllib.requests
和urllib.error
中的函数。