簡體   English   中英

Python 2.7無法從urllib.request中找到模塊Request

[英]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.requesturllib.error 將源轉換為Python 3時, 2to3工具將自動適應導入。

如果您正在遵循某種教程或課程,則可能需要安裝Python 3並繼續使用該版本。 您嘗試執行的代碼顯然是針對Python 3設計的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM