mysql-connector-python works in python console inside Pycharm but not in IDE

I installed mysql-connector-python 64bit from the MySQL site:

https://dev.mysql.com/downloads/connector/python/

I am able to execute this code PyCharm's Python console:

import mysql.connector
cnx = mysql.connector.connect(user='ven', password='test', host='127.0.0.1', database='ven_test')
cnx.close()

When I run the same code as a script in the IDE, I get the following message:

File "C:\Users\ven\Desktop\Projects\test\mysql.py", line 3, in <module>
mysql.connector.connect()
AttributeError: module 'mysql' has no attribute 'connector'

After bunch of Googling and researching... I ran this:

from distutils.sysconfig import get_python_lib
print(get_python_lib())

and get this: C:\Users\ven\Desktop\Projects\test\venv\Lib\site-packages

I also checked the Project Interpreter settings and mysql-connector-python is showing up.


I even tried:pip install mysql-connector-python
and basically it says the package has already been installed.

Can someone point me in the right direction.

Thanks!
-Ven


 

0
4 comments

Hello, 

 

Could you please provide:

1. A screenshot of your Project Interpreter including the list of installed packages

2. A screenshot of the Run/Debug configuration for the script https://www.jetbrains.com/help/pycharm/creating-and-editing-run-debug-configurations.html

3. Activate the same venv in a cmd (out of PyCharm) (please see https://intellij-support.jetbrains.com/hc/en-us/articles/360010202240) and run the script, provide me with a screenshot. 

0
Avatar
Permanently deleted user

I had the same problem using PyCharm. The code I wrote was:

import mysql.connector
db_connection = mysql.connector.connect(
host="localhost",
user="root",
passwd=""
)
print(db_connection)

and had the following message:

 

Traceback (most recent call last):
File "C:/Users/Guilherme Baird/PycharmProjects/PythonExercicios/pythonmysql.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'

 

Thanks for any help.

 

0

Hi, please follow the instructions provided above and let me know the results. 

0
Avatar
Permanently deleted user

hi there !!!

https://www.jetbrains.com/help/idea/installing-uninstalling-and-upgrading-packages.html kindly follow this link and install MySQL package. 

0

Please sign in to leave a comment.