No module named urllib3

2020-02-10 04:27发布

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.

5条回答
狗以群分
2楼-- · 2020-02-10 04:48

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.

查看更多
姐就是有狂的资本
3楼-- · 2020-02-10 04:50

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.

查看更多
叛逆
4楼-- · 2020-02-10 04:54
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.

查看更多
三岁会撩人
5楼-- · 2020-02-10 04:56

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.

查看更多
ゆ 、 Hurt°
6楼-- · 2020-02-10 05:02

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

查看更多
登录 后发表回答