Modulenotfounderror: no module named urllib3 [Solved]

Are you encountering Modulenotfounderror: no module named urllib3 error?

In this article, we will provide solutions to fix this error.

Apart from that, we will find the causes of this error.

But before jumping into error, we will briefly know what is urllib3 module.

urllib3 module

Particularly, Urllib3 is a Python module that provides a convenient way to handle HTTP requests and responses.

Including support for handling SSL certificates, connection pooling, timeouts, and retries.

It is built on top of the lower-level Python libraries such as httplib, ssl, and socket.

Furthermore, the urllib3 module is widely used in web scraping, web testing, and other applications that require making HTTP requests in Python.

Modulenotfounderror: no module named urllib3

The ModuleNotFoundError: No module named ‘urllib3’ error indicates that the module urllib3 is not installed before we import or we install it in an incorrect environment.

urllib3 module not found
urllib3 module not found

How to Solve Modulenotfounderror: no module named urllib3

Here are the possible solutions we have to fix Modulenotfounderror: no module named ‘urllib3’ error we might encounter.

  1. Install urllib3 module

    To get rid of the error we need to install it using the pip package manager. Simply, enter the following command in your command prompt.

    pip install urllib3

    install urllib3

    This command will install the pip install urllib3 in virtual environment of Windows, Linux, and macOS. Additionally, make sure that the pip manager is updated.

    However, if the pip package manager is not updated, use the following command:

    python -m pip install –upgrade pip
    pip install pandas

    update googleapiclient

    If you are using Anaconda or Miniconda as the package manager, you can run the command as indicated:

    conda install -c conda-forge urllib3

  2. Import the module

    Another reason for the error is that you forget to import the urllib3. To import the module use the following line:

    import urllib3

    import urllib3

    import urllib3 in pycharm

    This is also to check if the installation is successful at the same time to see if the error is resolved.

  3. Fix the Path

    If the error continues it could be urllib3 module was installed in the incorrect directory. Consequently every time we import it throws, Modulenotfounderror: no module named ‘urllib3.

    To fix this follow the given steps:

    1. Head over to the command prompt and open the folder where you installed Python and type where python.
    2. Open the scripts folder and copy the location. Make sure the folder has pip file.
    3. Now using the cd command and the location copied earlier open the Scripts directory.
    4. This time install the library using pip install urllib3 command.

    Once you have done following the steps above try to run your script again. The error should be removed.

  4. Check python version.

    Since we installed urllib3 module and the error still appear we must check their version to have the correct version and compatibility.

    Use the following command to check:

    python –version

    python version

Common causes of no module named urllib3

There are various reasons why we face Modulenotfounderror: no module named urllib3 error.

So here are the common reasons why it occurs:

  1. Missing or outdated urllib3 installation
    • If you have not installed urllib3 or have an outdated version, Python will not be able to find the module.
  2. Incorrect module name
    • Make sure that you are importing the module correctly in your code. Double-check your spelling and syntax.
  3. Virtual environment issues
    • Make sure that the environment is activated and that you have installed urllib3 within the environment.
  4. Path issues
    • Check that the path to the directory containing the urllib3 module is included in your system’s PATH environment variable.
  5. Module conflicts
    • It is possible that another module or package you have installed is conflicting with urllib3, causing Python to be unable to import the module.

Conclusion

In conclusion, Modulenotfounderror: no module named urllib3 error could be fixed by installing the missing module, checking the module name, installing in the correct path, and with compatible python and module versions.

We hope that this article has provided you with the information you need to fix this error and continue working with Python packages.

If you are finding solutions to some errors you’re encountering we also have Modulenotfounderror: no module named ‘taming’.

Frequently Asked Questions

What is Python ModuleNotFoundError and what causes it?

ModuleNotFoundError (a subclass of ImportError) is raised when Python cannot find the module you tried to import. Common causes: the package isn’t installed (pip install missing), wrong virtual environment activated, typo in module name, or Python can’t find your local module on the import path. The error message names exactly which module is missing.

How do I fix ‘ModuleNotFoundError: No module named X’?

Run pip install X first. If that succeeds but you still get the error, check which Python you’re using (which python OR python –version) vs which pip (which pip OR pip –version), they must match. Common gotcha: pip points to system Python 3.9 but you’re running python3.11 in a venv. Inside the venv, use python -m pip install X to be sure pip matches the active Python.

Why does my code work in one environment but not another?

Different Python versions or different installed packages. To diagnose: pip freeze > requirements.txt on the working environment, then pip install -r requirements.txt on the broken one. Use virtualenv (python -m venv venv) or conda for every project to avoid system-wide package collisions.

Is ModuleNotFoundError the same as ImportError?

ModuleNotFoundError is a subclass of ImportError added in Python 3.6. It specifically means ‘no such module exists.’ Plain ImportError covers a wider set: module exists but a name inside it can’t be imported (e.g. ‘cannot import name X from Y’). except ImportError catches both; except ModuleNotFoundError catches only the missing-module case.

Where can I find more ModuleNotFoundError fixes?

Browse the ModuleNotFoundError reference hub for 198+ specific module fixes (TensorFlow, Flask, Django, pandas, numpy, etc.). For related issues see ImportError. For broader Python setup see Python Tutorial hub.

Glay Eliver

Programmer & Technical Writer at PIES IT Solution

Glay Eliver is a programmer and writer at PIES IT Solution, author of over 600 tutorials at itsourcecode.com. Specializes in JavaScript tutorials, Microsoft Office how-tos (Excel, Word, PowerPoint), and Python error debugging covering ImportError, TypeError, AttributeError, ModuleNotFoundError, and JavaScript ReferenceError. Authored several of the site’s highest-traffic Excel and MS Office reference articles.

Expertise: JavaScript · MS Excel · MS Word · MS PowerPoint · Python · Python ImportError · Python TypeError · Python AttributeError · ModuleNotFoundError · JavaScript ReferenceError · Pygame  · View all posts by Glay Eliver →

Leave a Comment