Python 3.x导入错误SyntaxError [英] Python 3.x import error SyntaxError

查看:109
本文介绍了Python 3.x导入错误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一样使用printException.它还使用urllib2库,该库在Python3中分为urllib库的两部分.
最好使用Python2(Python2.7)完成工作,或者您必须修改builtwith的源代码,即将所有print语句更改为print()函数,将except Exception, e更改为except Exception as e ,并将所有urllib2函数更改为urllib.requestsurllib.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆