MySQL Forums
Forum List  »  Connector/Python

import sql connector
Posted by: Paul Fenwick
Date: April 17, 2013 08:48AM

Hi Folks

I amusing Windows 7 x64, Python 3.3.1, mysql connector 1.0.9

I have tried my code line by line in the Python shell which works fine, I can import the connector and connect to the database and fetch back data, BUT when I save the code as a .py the import mysql.connector does not want to work for some reason, I do have the Path variable setup and when I installed the mySQL connector it placed the relevant files in my Python install path \Lib\site-pacakges folder.

import mysql.connector #this is failing as a .py but works in the shell

cnx = mysql.connector.connect(user='root', password='mypassword', host='my_ip_address', database'name_of_database') #this works in the shell

cursor = cnx.cursor()

I have also tried my .py with just:

import mysql.connector

I get the following error:

Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1518, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Paul\Desktop\scripts\mysql.py", line 2, in <module>
import mysql.connector
File "C:\Users\Paul\Desktop\scripts\mysql.py", line 2, in <module>
import mysql.connector
ImportError: No module named 'mysql.connector'; mysql is not a package



I have tried the msi install and the independent install

Options: ReplyQuote


Subject
Written By
Posted
import sql connector
April 17, 2013 08:48AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.