2

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
3
  • 2
    What environment are you using? Pycharm can handle mutiple environments. You can find them in the right bottom corner. Did you check, you installed it correctly? Pycharm let's you install packages using it's GUI. Also check if your configuration is set to the right interpreter (Run - Edit Confuguration) Commented Oct 21, 2019 at 8:24
  • 1
    I am using pycharm 3.7 and for that I have installed pip3. Commented Oct 21, 2019 at 8:35
  • 1
    Try using PyCharm GUI for installing your packages. Do other imported modules work? Commented Oct 21, 2019 at 9:24

5 Answers 5

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

Great!! now it worked form me. Thanks a ton for your help.
Glad that I helped you! Can you select it as an answer?
4

For me the issue was that I had installed the mysql package but not mysql-connector

Comments

2

I faced the same issue when running the program in Pycharm, there is a file in venv >> scripts >> pyvenv.cfg which had include-system-site-packages = false. But once it is changed and set to true it worked for me.

version_info = 3.10.0.final.0 include-system-site-packages = true

1 Comment

This worked for me! Appreciate you sharing your knowledge!
1

Make sure you're using correct python interpreter. Example: On Ubuntu operating system, for python2 there's pip, but for python3 there's pip3 using the wrong pip will make your packages unavailable for the other python version.

1 Comment

I am using windows 10 and for python 3 I am using pip3.
0

Check your python install version. If you have multiple versions be sure to use the correct pip version related.

pip show mysql-connector-python

# or
 
pip3 show mysql-connector-python

If this returns:

WARNING: Package(s) not found: mysql-connector-python

Then run

pip install mysql-connector-python

# or

pip3 install mysql-connector-python

Rerun the first command and you should now see something like this:

>>> pip show mysql-connector-python
Name: mysql-connector-python
Version: 8.3.0
Summary: MySQL driver written in Python
Home-page: http://dev.mysql.com/doc/connector-python/en/index.html
Author: Oracle and/or its affiliates
Author-email:
License: GNU GPLv2 (with FOSS License Exception)
Location: C:\Users\JayRizzo\AppData\Roaming\Python\Python311\site-packages
Requires:
Required-by:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.