来自urllib.request的Python 3.6.2导入urlopen

时间:2017-08-05 06:44:04

标签: python-3.x

这是我想要开始使用的脚本。我在一些地方看到这是一个工作版本。任何人都知道为什么这不会在我的mac系统上执行。我愿意接受所有想法来解决这个问题。

from urllib.request import urlopen
html = urllib.request.urlopen("http://www.google.com")
print(html.read())

我在执行时将其作为输出。

Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> 
====== RESTART: /Users/John/Documents/python_function_john/scraping.py ======
Traceback (most recent call last):
  File "/Users/John/Documents/python_function_john/scraping.py", line 1, in <module>
    from urllib.request import urlopen
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 88, in <module>
    import http.client
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 71, in <module>
    import email.parser
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/email/parser.py", line 12, in <module>
    from email.feedparser import FeedParser, BytesFeedParser
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/email/feedparser.py", line 27, in <module>
    from email._policybase import compat32
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/email/_policybase.py", line 9, in <module>
    from email.utils import _has_surrogates
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/email/utils.py", line 30, in <module>
    import datetime
  File "/Users/John/Documents/datetime.py", line 4
    print a.time()
          ^
SyntaxError: invalid syntax 

1 个答案:

答案 0 :(得分:0)

最好安装Anaconda;此应用程序在您的计算机上安装了一些Python包。然后在Conda Prompt中写下以下行:

conda install -c conda-forge requests

毕竟,使用已安装Anaconda的Spyder应用程序。