Python 3.x导入错误SyntaxError [英] Python 3.x import error SyntaxError
问题描述
我正在使用macOS Sierra.导入builtwith
时,出现以下错误:
I'm using macOS Sierra. When importing builtwith
I get these following error:
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
我该怎么做才能正确导入它?
What I can do to import it correctly?
推荐答案
这是因为您安装的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
中的函数.
This is because the builtwith
package you installed is developed by Python2, not Python3. So it uses print
and Exception
as Python2 does. It also uses urllib2 library which is seperated into two part of urllib library in Python3.
It's better to use Python2 (Python2.7) to finish the work or you have to modify the source code of builtwith
, that is, change all print
statement into print()
function, change except Exception, e
into except Exception as e
, and change all urllib2
functions into functions in urllib.requests
and urllib.error
.
这篇关于Python 3.x导入错误SyntaxError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!