ImportError:没有名为response的模块

时间:2016-07-14 12:21:07

标签: python virtualenv

我在虚拟环境中运行py.tests。得到

ImportError: No module named responses
pip冻结之后

我看到安装了响应

pip freeze                                                   ✱
cookies==2.2.1
funcsigs==1.0.2
mock==2.0.0
pbr==1.10.0
py==1.4.31
pymongo==2.7.2
pytest==2.9.2
requests==2.10.0
responses==0.5.1
six==1.10.0

运行测试:

like so py.test --verbose tests/

2 个答案:

答案 0 :(得分:0)

我有同样的问题。

不确定是什么罪魁祸首,但是我之后就解决了:

  1. numRows = len(driver.find_elements_by_xpath('/html/body/div[2]/div/form[3]/div[2]/div[1]/div/div/div/div[2]/div[4]/section[1]/div[2]/div/div/table/tbody/tr')) numColumns = len(driver.find_elements_by_xpath('/html/body/div[2]/div/form[3]/div[2]/div[1]/div/div/div/div[2]/div[4]/section[1]/div[2]/div/div/table/thead/tr[2]/th')) print(numRows) # Prints 139 print(numColumns) # prints 21 for i in range(numRows + 1): df = [] value = driver.find_element_by_xpath("/html/body/div[2]/div/form[3]/div[2]/div[1]/div/div/div/div[2]/div[4]/section[1]/div[2]/div/div/table/tbody/tr['{}']/td[16]".format(i)) df.append(value.text) print(df) 在我的虚拟环境中(不言而喻,但出于完整性考虑,我将其添加)
  2. 已保存的需求pip install responses
  3. 已停用(pip freeze > requirements.txt),已删除(deactivate)并重新创建了虚拟环境(rm -rf venv
  4. 激活了新的虚拟环境virtualenv -p $(which python3) venv
  5. 重新安装要求. venv/bin/activate

答案 1 :(得分:0)

我想这是由安装响应时的错误引起的:

ERROR: responses 0.12.1 has requirement urllib3>=1.25.10, but you'll have urllib3 1.22 which is incompatible.

如果您更新 urllib3,您会收到此错误:

ERROR: requests 2.18.4 has requirement urllib3<1.23,>=1.21.1, but you'll have urllib3 1.26.2 which is incompatible.

Yet another reason to move to httpx

所以你可以做的是安装旧的 responses 版本:

responses<0.10.8