Python 没有名为 urllib3 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42651145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:59:42  来源:igfitidea点击:

No module named urllib3

pythonxmlpython-2.7urllib3

提问by Jeremy Real

I wrote a script to call an API and ran it successfully last week. This week, it won't run. I get back the following error message:

我写了一个脚本来调用 API 并在上周成功运行了它。本周,它不会运行。我收到以下错误消息:

Traceback (most recent call last):
  File "user_audit.py", line 2, in <module>
    import requests
  File "c:\Python27\lib\site-packages\requests\__init__.py", line 60, in <module>
    from .packages.urllib3.exceptions import DependencyWarning
  File "c:\Python27\lib\site-packages\requests\packages\__init__.py", line 29, in <module>
    import urllib3
ImportError: No module named urllib3

I've confirmed that packages is up to date, tried uninstalling and reinstalling it, but nothing has worked so far. Can someone help?

我已经确认软件包是最新的,尝试卸载并重新安装它,但到目前为止没有任何效果。有人可以帮忙吗?

ADDENDUM

附录

I installed urllib3 as suggested by @MSHossain, but then got another error message. The new message referenced another file that I'd written, which had created a Python compiled file. The other file was using smptlib to attempt to send an email. I don't understand how this would happen, but I deleted the other file and my script ran without any problems. I've accepted the answer below as I was able to pip install urllib3, but it should have already been included in the requests module.

我按照@MSHossain 的建议安装了 urllib3,但随后收到了另一条错误消息。新消息引用了我编写的另一个文件,该文件创建了一个 Python 编译文件。另一个文件正在使用 smptlib 尝试发送电子邮件。我不明白这是怎么发生的,但我删除了另一个文件,我的脚本运行没有任何问题。我已经接受了下面的答案,因为我能够 pip install urllib3,但它应该已经包含在请求模块中。

采纳答案by Shakhawat Hossain

either urllib3 is not imported or not installed.

urllib3 未导入或未安装。

to import ,write import urllib3at the top of the file to install write pip install urllib3into terminal. you may not activate environment variable correctly. to activate environment variable , write source env/bin/activateinto terminal. here envis environment variable name.

要导入, 在文件顶部写入 import urllib3以安装写入pip install urllib3到终端。您可能没有正确激活环境变量。要激活环境变量,请将source env/bin/activate写入终端。这里env是环境变量名称。

回答by crizCraig

pip install urllib3 

The reason it broke is that I had installed an incompatible version of urllib3as a transient dependency of awscli. You'll see such conflicts when you rerun the install.

它崩溃的原因是我安装了一个不兼容的版本urllib3作为awscli. 当您重新运行安装时,您会看到此类冲突。

回答by Shakhawat Hossain

set you environment by writing source env/bin/activateif envnot found write virtualenv envfirst then source env/bin/activate, then check pip freezeif urllib3 not found there then reinstall urllib3, hope it helps.

设置你写环境源ENV /斌/激活如果ENV没有找到写的virtualenv ENV第一则源ENV /斌/启动,然后检查PIP冻结如果urllib3没有找到然后重新安装urllib3,希望它帮助。

回答by vamosrafa

Few minutes back, I faced the same issue. And this was because, I used virtual environment. I believe that due to venv directory, the pip installed might have stopped working.

几分钟前,我遇到了同样的问题。这是因为,我使用了虚拟环境。我相信由于 venv 目录,安装的 pip 可能已停止工作。

Fortunately, I have setup downloaded in my directory. I ran the setup and chose the option to repair, and now, everything works fine.

幸运的是,我已经在我的目录中下载了安装程序。我运行了设置并选择了修复选项,现在一切正常。

回答by JochemQuery

For me in PyCharm I had to put import urllib3at the top of the file as mentioned earlier then PyCharm gave the option to import. Even after installing it with pip

对于我在 PyCharm 中import urllib3,如前所述,我必须将其放在文件的顶部,然后 PyCharm 提供了导入选项。即使在安装后 pip