[Tutor] ImportError: No module named connect
Tommy Peterson
stpetersn at hotmail.com
Tue Nov 3 13:22:21 EST 2015
As I typed this out I double checked something. I resolved my own problem. Should have stepped back before posting.
It is
import mysql.connector
not
import mysql.connection
From: stpetersn at hotmail.com
To: tutor at python.org
Subject: ImportError: No module named connect
Date: Tue, 3 Nov 2015 12:59:26 -0500
I have been trying to install the MySQL Connect module for a day and a half.
First I got an error saying that "No module named mysql" was installed. After a lot of trial and error I got passed that. I realized that because I have python installed in /usr/local that I needed to build and then install the library into site-packages where Python was looking. But now it appears that the submodule "connect" cannot be located.
Some people have suggested online that I needed to make sure the module was added to the system path by doing this:
import sys
sys.path.insert(1,'//usr/local/lib/python2.4/site-packages/mysql')
import mysql
Some have suggested that I needed to edit the __init__.py file in /mysql/ with this:
from pkgutil import extend_path
path = extend_path(path, name)
But after I built and then installed pointing to my site-packages directory the __init__.py file in /usr/local/lib/python2.4/site-packages/mysql/ has that code already. The __init__.py in mysql/connector/ has a lot of stuff. It uses dot notation as well which is beyond my rudimentary Python knowledge: for example:
from . import version
from .connection import MySQLConnection
It appears this is related to the install and that I am using /usr/local/lib/python2.4/site-packages. But I am running out of ideas to try. I am not Python expert as you can tell.
Any suggestions?
Again the error in my script where I try to import mysql.connection to connect to mysql is:
import mysql.connect
ImportError: No module named connect
The installation instructions are :
http://dev.mysql.com/doc/connector-python/en/connector-python-introduction.html
Also I have tried installing it via yum. No go there either.
More information about the Tutor
mailing list