我正在編寫由其他人編寫的Python腳本。我試圖讓它在本地開發機器上運行時沒有任何問題。在Python 2.7中導入'urllib3.util'失敗?
我已經安裝了腳本所需的模塊(請求,urllib3和oath2),但是我收到以下錯誤,我正在努力解決;
Traceback (most recent call last):
File "/home/saeed/ps4/scrape/run.py", line 2, in <module>
import get_data as gd, time
File "/home/saeed/ps4/scrape/get_data.py", line 8, in <module>
import sys, oauth2, requests, json
File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 58, in <module>
from . import utils
File "/usr/local/lib/python2.7/dist-packages/requests/utils.py", line 25, in <module>
from .compat import parse_http_list as _parse_list_header
File "/usr/local/lib/python2.7/dist-packages/requests/compat.py", line 7, in <module>
from .packages import chardet
File "/usr/local/lib/python2.7/dist-packages/requests/packages/__init__.py", line 3, in <module>
from . import urllib3
File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/__init__.py", line 16, in <module>
from .connectionpool import (
File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py", line 36, in <module>
from .connection import (
File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connection.py", line 43, in <module>
from .util import (
ImportError: No module named util
腳本由三個文件組成; run.py,get_data.py和incr.py.在run.py import語句是:
import get_data as gd, time
在get_data.py:
import sys, oauth2, requests, json
在incr.py:
import time
我認爲我必須安裝一個名爲模塊'UTIL'。我搜索了這個模塊並找不到它,因此我認爲這似乎是一個更深層次的問題,而不僅僅是安裝模塊。
如果有人能指出我解決問題的正確方向,我將非常感激。我正在使用Python 2.7.3。
有一個在urllib3封裝模塊'util.py',是的。 – wim
如果您在交互式解釋器中執行「導入urllib3.util」,會發生什麼情況? – wim
我認爲命名空間不正確。在你使用導入的地方顯示一些代碼。 – fledgling