No module named urllib3

Jeremy Real picture Jeremy Real · Mar 7, 2017 · Viewed 73.4k times · Source

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.

Answer

Shakhawat Hossain picture Shakhawat Hossain · Mar 7, 2017

Either urllib3 is not imported or not installed.

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.