mysql.connector shows the 'connect' module not available

Asked by Atul

Hello,

I have been using mysql connector from past few months. It was working fine until one fine day I did a fresh installation to upgrade my OS (Ubuntu 12.04). After that I installed the mysql connector and found this annoying problem. I am being able to import 'mysql.connector' module successfully but it gives the following error:

>>> import mysql.connector as sql
>>> conn=sql.connect(host='127.0.0.1', user='abc', passwd='xyz')
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    conn=sql.connect(host='127.0.0.1', user='abc', passwd='xyz')
AttributeError: 'module' object has no attribute 'connect'
>>>

Please help me.

Atul

Question information

Language:
English Edit question
Status:
Solved
For:
MySQL Connector/Python Edit question
Assignee:
Geert JM Vanderkelen Edit question
Solved by:
Atul
Solved:
Last query:
Last reply:
Revision history for this message
Geert JM Vanderkelen (geertjmvdk) said :
#1

You are using pyshell, not sure if that matters though.

Try using the normal python shell. I did following on Mac:

shell> python
>>> import mysql.connector as sql
>>> sql.connect(database="test")
<mysql.connector.connection.MySQLConnection object at 0x10f0c4750>
>>> sql.foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'foo'
>>>

Doing the above on Ubuntu 12.04 gave the same result.

Revision history for this message
Geert JM Vanderkelen (geertjmvdk) said :
#2

Just to confirm that installing IDLE 2.7.3 on Ubuntu 12.04 I could load mysql.connector and do 'import .. as ..'

Revision history for this message
Atul (atulkakrana) said :
#3

@Geert: Thanks for replying. I forgot to mention that I am using Python 3.2 and I get the same error even on terminal. Also eclipse gives the same error. Error from terminal:

Python 3.2.3 (default, Apr 12 2012, 19:08:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector as sql
>>> sql.connect(database="test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'connect'
>>>

I confirm that it works with python 2.7 on terminal, IDLE2.7 and Eclipse.

The problem is that with python3.2 I am being able to import it successfully but while connecting it gives the error:

AttributeError: 'module' object has no attribute 'connect'

Awaiting reply

Atul

Revision history for this message
Atul (atulkakrana) said :
#4

@Geert: Just to mention that I am using the most latest build from the 'Launchpad'.

Atul

Revision history for this message
Atul (atulkakrana) said :
#5

@Geert: I have fixed the problem. The files under 'mqsql>connector' directory had only write permissons for 'user' so changing the permissions to read and execute solved the issue.

I am not sure why the permissions were screwed as I was just installing the normal way it worked before on ubuntu11.10.

Thanks

Atul