Search code examples
pythonmysql-python

How to fix: no module named 'mysql'


I want to connect my MYSQL DB to the python DB.I have installed pip mysql connector already.I opened pycharm and ran "import mysql.connector". Upon executing this code,I received 'no such module named mysql' error.

import mysql.connector

Solution

  • I don't know what you have tried so far, so I'm not sure if this will solve your problem but check your configuration.

    Also, I'm not quite sure what PyCharm 3.7 is? Did you mean Python 3.7 and PyCharm 2019? (For this answer, I'm using PyCharm Professional 2019 and Python 3.6


    Check your Settings

    • First check your current interpreter. It can be found on the right side of your windows, bottom corner. enter image description here

    • Open Interpreter Settings. A window with a list will pop up, showing the currently install packages. Start typing the name of your package you are looking for. If it's not found, you must install it. enter image description here

    • For installing, click on the small plus-Sign on right of the list. The window called Available Packages will appear. Here search for your desired package. Available Packages Window

    • Click on Install Packages

    • Check your configuration: Under Run -> Edit Configurations (or the Dropdown menu near the Run-Button) make sure you have selected the right Python interpreter. It must your previously selected interpreter. Run-Config