Modulenotfounderror no module named pymysql [SOLVED]

The Modulenotfounderror no module named PyMySQL is a common error most python programmers faced either beginner or developer users.

In this article, we will provide solutions to fix this error Modulenotfounderror: no module named PyMySQL. Apart from it, we look at possible causes of why this error occurs.

Thus, prior to that here is a brief understanding about this module…

What is PyMySQL module?

PyMySQL is a Python library that allows a Python program to communicate with a MySQL database. Whereas MySQL is a widely used open-source relational database management system for storing and managing data in web applications.

Additionally, PyMySQL provides a straightforward and easy-to-use interface to interact with MySQL databases.

PyMySQL is a pure-Python implementation of the MySQL protocol and is compatible with Python 2.7, 3.4, and above. It supports all of the features of MySQL, including transactions, prepared statements, and stored procedures.

Moreover, PyMySQL can be used to create, modify, and delete database tables, as well as to insert, update, and retrieve data from them.

What is Modulenotfounderror no module named pymysql ?

The Modulenotfounderror no module named pymysql is an error that typically occurs when the Python interpreter cannot find the pymysql module, which is a third-party library used for connecting to MySQL databases.

pymysql error

Common causes of no module named pymysql

Here are some common causes of the error no module named pymysql:

  1. Missing Installation
    • One of the most common reasons for the ModuleNotFoundError is the absence of the pymysql module on your system.
  2. Wrong Installation Location
    • It’s also possible that the pymysql module was installed in a different location from where your Python interpreter is looking for it.
  3. Typo in import statement
    • The error can also occur if there is a typo in the import statement, for example, if the module name is misspelled.
  4. Incompatibility Issues
    • In some cases, the error can arise due to incompatibility issues between pymysql and other modules or the Python version being used.
  5. Corrupt Installation
    • If the pymysql module was installed correctly but is still not being found, it could be due to a corrupted installation of the module.

How to solved modulenotfounderror: no module named ‘pymysql’

Here are some solutions you can consider to fix the error.

  1. Checked if the module is installed.

    Check if pymysql is installed on your system by running the following command in your terminal or command prompt:

    pip show pymysql

    pymysql is installed

    If it is not installed it will show warnings:

    pymysql module is not installed

  2. Install PyMySQL module

    You can install it using pip, which is a package manager for Python. Open a command prompt or terminal and type the following command:

    pip install pymysql

    install pymysql

  3. Checked Python Version

    If you have multiple Python versions installed on your system, make sure you are installing pymysql for the correct version.

    Use the following command:

    python --version

    python version

  4. Check module name

    Another common cause of the “Modulenotfounderror no module named pymysql” error is a typo in the module name. Make sure that you have spelled the module name correctly in your Python script.

  5. Import the module

    Make sure you are importing pymysql correctly in your Python script. The correct way to import the module use the following command:

    import pymysql

    Import pymysql successfully

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

Final Thoughts

The “Modulenotfounderror no module named pymysql” error message is a common issue encountered by Python developers working with MySQL databases. The error message usually indicates that the pymysql module is not installed or cannot be found by Python.

In this article, we have discussed the common causes of the error and how to fix them. If you encounter an error message, follow the steps outlined in this article to resolve the issue and get back to coding.

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’.

Related Python Tutorials

Root causes of Modulenotfounderror no module named pymysql [SOLVED]

  • Package not installed. The module you’re importing was never installed in the current environment. Fix: pip install <package-name>.
  • Wrong virtual environment active. You installed in one venv but running from a different environment. Verify with which python and which pip.
  • Multiple Python versions. pip installs for one Python, but you’re running a different version. Use python -m pip install <package> to force it.
  • Typo in module name. Case-sensitive imports. Beautiful_Soup vs beautifulsoup4 vs bs4. Check the actual import name in the package docs.
  • Package uninstalled or corrupted. Try pip install –force-reinstall <package> to freshen the install.

Step-by-step debugging

  1. Verify Python path. import sys; print(sys.executable) shows which Python is running.
  2. Check installed packages. pip list | grep <package> confirms it’s actually installed.
  3. Match environment. Confirm the terminal that ran pip install is the same environment your code runs in.
  4. Reinstall cleanly. pip uninstall <package> then pip install <package>.
  5. Try python -m install. python -m pip install <package> avoids PATH mismatches.

Working install pattern

# Create fresh environment (recommended for any new project)
python -m venv myenv
source myenv/bin/activate  # Windows: myenv\Scripts\activate

# Install requirements
pip install --upgrade pip
pip install <package-you-need>

# Verify install
pip list | grep <package>
python -c "import <package>; print(<package>.__version__)"

When the error persists

  • Check for typos. Module names can differ from PyPI names (opencv-python vs cv2, beautifulsoup4 vs bs4).
  • Update Python or downgrade the package. Some packages have version-specific compatibility.
  • Restart the interpreter or kernel. Jupyter and IDEs cache import state.
  • Check for conda/pip conflicts. If using Anaconda, prefer conda install <package> over pip.

Frequently Asked Questions

What Python version does this tutorial target?
This tutorial targets Python 3.10 or higher. Most examples work on 3.8+, but newer features (match statements, pipe union types, structural pattern matching) need 3.10+. For deep learning content, Python 3.11 is recommended for best performance.
How do I install Python for this tutorial?
Download Python 3.11 or higher from python.org. On Windows, tick ‘Add to PATH’ during install. On Mac use Homebrew (brew install python). On Linux use your package manager or pyenv for version management.
Do I need pip and virtual environments?
Yes. pip comes with Python. For any project beyond a single script, create a virtual environment: python -m venv venv, then activate and pip install dependencies. This keeps project libraries isolated.
Can I use this in a Jupyter notebook or Google Colab?
Most examples run in both. Colab is great for ML tutorials since it provides free GPU access. Jupyter is better for local iterative development. Just paste the code into a cell and run.
Where can I find more Python practice projects?
Browse itsourcecode.com Python Projects for 250+ free capstone-ready systems (sentiment analysis, image classification, chatbots, LangChain apps). Each includes full source code, dataset links, and installation instructions.

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