简体   繁体   English

没有名为 urllib3 的模块

[英]No module named urllib3

I wrote a script to call an API and ran it successfully last week.我写了一个脚本来调用一个 API 并在上周成功运行。 This week, it won't run.这周,它不会运行。 I get back the following error message:我收到以下错误消息:

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.我按照@MSHossain 的建议安装了 urllib3,但随后收到了另一条错误消息。 The new message referenced another file that I'd written, which had created a Python compiled file.新消息引用了我编写的另一个文件,该文件创建了一个 Python 编译文件。 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.另一个文件使用 smptlib 尝试发送 email。我不明白这是怎么发生的,但我删除了另一个文件并且我的脚本运行没有任何问题。 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.我已经接受了下面的答案,因为我能够 pip 安装 urllib3,但它应该已经包含在请求模块中。

Either urllib3 is not imported or not installed. urllib3 未导入或未安装。

To import, use要导入,请使用

import urllib3

at the top of the file.在文件的顶部。 To install write:要安装写:

pip install urllib3

into terminal.进入终端。

It could be that you did not activate the environment variable correctly.可能是您没有正确激活环境变量。 To activate the environment variable, write要激活环境变量,请写入

source env/bin/activate

into terminal.进入终端。 Here env is the environment variable name.这里env是环境变量名称。

pip install urllib3 

The reason it broke is that I had installed an incompatible version of urllib3 as a transient dependency of awscli .它崩溃的原因是我安装了一个不兼容的urllib3版本作为urllib3的临时依赖awscli You'll see such conflicts when you rerun the install.当您重新运行安装时,您会看到此类冲突。

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

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.我运行了设置并选择了修复选项,现在一切正常。

For me in PyCharm I had to put import urllib3 at the top of the file as mentioned earlier then PyCharm gave the option to import.对于我在 PyCharm 中, import urllib3 ,我必须将import urllib3放在文件顶部,然后 PyCharm 提供了导入选项。 Even after installing it with pip即使在用pip安装之后

This happened for me too. 这件事也发生在我身上。 When I went to the terminal, tried installing urllib3, it said "Requirement already satisfied". 当我去终端时,尝试安装urllib3,它说“要求已经满足”。 But PyCharm was throwing an error saying urllib3 isn't available. 但是PyCharm抛出一个错误,说urllib3不可用。 I have written import urllib3 on the top of the file, and then it gave me an option to install the library, which eventually worked. 我已经在文件的顶部编写了import urllib3,然后它给了我一个安装库的选项,该库最终成功了。 Thanks for the help @JochemQuery! 感谢您的@JochemQuery帮助!

我通过运行解决了它

pip install --upgrade requests

I already had it installed.我已经安装了它。 Solved it by running pip install --upgrade urllib3通过运行pip install --upgrade urllib3解决了它

Hope it helps someone:)希望它可以帮助某人:)

Reinstalling urllib3 solves my problem.重新安装 urllib3 解决了我的问题。 Run:跑步:

pip uninstall urllib3
pip install urllib3

For the sake of completness.为了完整起见。 It means the python installation you are using does not have the package installed, be sure you are using the same python installation as the one where you are installing the package .这意味着您正在使用的 python 安装没有安装 package,请确保您使用的 python 安装与安装 package 的安装相同

For me what was happening is that I had a virtual environment made with pyenv , even when the virtual environment had the package installed and in its latest version, it was not found because somehow the underlaying python install was used and not the one where I had the urllib3 installed.对我来说,发生的事情是我有一个用pyenv 创建的虚拟环境,即使虚拟环境安装了 package 并且是最新版本,也没有找到它,因为不知何故使用了底层 python 安装,而不是我安装的那个安装了 urllib3。

Solution: Use the absolute path to the python binary :解决方案:使用 python 二进制文件的绝对路径

/home/[username]/.pyenv/versions/[envname]/bin/python python-script.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ImportError:没有名为urllib3的模块,已经安装了urllib3 - ImportError: no module named urllib3, urllib3 is already installed 没有名为“ urllib3” Selenium Python的模块 - No module named “urllib3” Selenium Python ModuleNotFoundError:没有名为“ urllib3.exceptions”的模块; &#39;urllib3&#39;不是一个软件包 - ModuleNotFoundError: No module named 'urllib3.exceptions'; 'urllib3' is not a package ImportError:安装pip时没有名为urllib3的模块 - ImportError: No module named urllib3 when installing pip 尝试安装mysql-python:“没有名为urllib3的模块” - Trying to install mysql-python: “No module named urllib3” 无法将请求导入 Python:ImportError 没有名为 urllib3 的模块 - Can't Import Requests into Python: ImportError no module named urllib3 无法在Ubuntu中使用pip创建虚拟环境 - 没有名为urllib3的模块 - Can't create virtual env with pip in Ubuntu - No module named urllib3 导入客户端时,带有twilio v 6.5.2的python v 2.7.13与找不到urllib3的模块 - python v 2.7.13 with twilio v 6.5.2 cannot find module named urllib3 when importing Client urllib、urllib2、urllib3 和 requests 模块之间有什么区别? - What are the differences between the urllib, urllib2, urllib3 and requests module? 在python中使用urllib3模块而不是请求 - using urllib3 module instead of requests in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM