【发布时间】:2018-05-27 12:44:01
【问题描述】:
我搜索了一些网络,但不适合我的情况。它在 jupyter notebook 和 shell 上运行良好,但在 pycharm 2017.1.3 上运行良好。版本是 Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
from urllib import request
with request.urlopen('https://api.douban.com/v2/book/2129650') as f:
data = f.read()
print('Status:', f.status, f.reason)
for k, v in f.getheaders():
print('%s: %s' % (k, v))
print('Data:', data.decode('utf-8'))
错误的堆栈跟踪
"D:\Program Files (x86)\Anaconda3\python.exe" D:/pyProject/liao/usual/urllib.py
Traceback (most recent call last):
File "D:/pyProject/liao/usual/urllib.py", line 8, in <module>
from urllib import request
File "D:\pyProject\liao\usual\urllib.py", line 8, in <module>
from urllib import request
ImportError: cannot import name 'request'
Process finished with exit code 1
【问题讨论】:
-
您是否有可能在其他系统上使用过 Python 2.7?
urrlib包已更改...见顶部 docs.python.org/2.7/library/urllib.html -
@simonz 不,我只得到原始的 python 3.6.1 和 anaconda3 python 3.6.0,而 pycharm 解释器使用的是 anaconda3 python
-
@simonz 你确定你提到的是这个问题的正确信息吗?
-
您已将自己的程序命名为 urllib.py - 您的导入在实际的
urllib模块之前发现了它! -
@jasonharper 我的错误..这确实有道理..请回答并被接受
标签: python-3.x urllib