No module named urllib3

拟墨画扇 提交于 2019-11-27 17:39:50

问题


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:

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.


回答1:


either urllib3 is not imported or not installed.

to import ,write import urllib3 at the top of the file to install write pip install urllib3 into terminal. you may not activate environment variable correctly. to activate environment variable , write source env/bin/activate into terminal. here env is environment variable name.




回答2:


set you environment by writing source env/bin/activate if env not found write virtualenv env first then source env/bin/activate , then check pip freeze if urllib3 not found there then reinstall urllib3, hope it helps.




回答3:


pip install urllib3 

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




回答4:


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.

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




回答5:


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. Even after installing it with pip



来源:https://stackoverflow.com/questions/42651145/no-module-named-urllib3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!