[英]Python 2.7 cannot find module Request from urllib.request
嘗試從Python 2.7中的urllib.request
導入Request
,無法找到該包。
>>> from urllib.request import Request
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named request
Python 2中沒有urllib.request
模塊,該模塊僅存在於Python 3中 。
使用urllib2
代替:
from urllib2 import Request
從模塊文檔的頂部:
注意:
urllib2
模塊已在Python 3中分為幾個名為urllib.request
和urllib.error
。 將源轉換為Python 3時,2to3
工具將自動適應導入。
如果您正在遵循某種教程或課程,則可能需要安裝Python 3並繼續使用該版本。 您嘗試執行的代碼顯然是針對Python 3設計的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.