On Tue, Nov 03, 2015 at 12:59:26PM -0500, Tommy Peterson wrote:
> I have been trying to install the MySQL Connect module for a day and a half. 

I see that you believe that you have solved your problem ("from mysql 
import connector" rather than "connect" or "connection") but for the 
record you have other problems. 

I recognise that, right now, you probably have a working system and the 
last thing you want to do is mess with it, but trust me, whoever has to 
maintain your system in the future is going to be *utterly confused* by 
your setup. If you choose to ignore this ("hey, my system works, I'm not 
going to mess with it") at least copy this post into your site wiki (if 
you have one) or put it in a README file somewhere where the next guy 
(or even you, in the future) can see it. Because your Python setup is 
*seriously* weird.

You talk about using the site-packages in python2.4. Why are you using 
Python 2.4? That's ancient. I see that you are using a Redhat based 
system, as you refer to yum, but it doesn't make sense that you have 
Python 2.4 in /usr/local/lib.

In old Centos/Fedora/Redhat systems, where Python 2.4 is still used, we 
have the path set here:

/usr/lib/python2.4/

*not* /usr/local/lib. Perhaps you are using a more recent RH-based 
system, which defaults to Python 2.6 or 2.7. So why have you installed 
2.4? It's so old that the mysql package won't work. I know it won't work 
because mysql __init__.py includes the dot notation

from . import version

which is a SyntaxError in Python 2.4.

So it appears that:

- you have installed Python 2.4 in a non-standard place;
- installed a package for 2.6 or higher in the 2.4 site-packages;
- and are running Python 2.6 or higher using the 2.4 site-packages.

Anyone who has to maintain or administer your system is going to be 
horribly confused.

Despite the references to 2.4 site-packages, I expect you are using 
Python 2.6 or higher. You ought to be able to install the Python mysql 
library using yum. On my Centos system, I can do this:

[root@ando ~]# yum search mysql-python
[...]
MySQL-python.i386 : An interface to MySQL
python26-mysqldb.i386 : An interface to MySQL


so all I need to do is:

    sudo yum install mysql-python

to install into the system Python 2.4, or:

    sudo yum install python26-mysqldb

to install into the yum-provided Python 2.6 installation. I don't know 
which precise RH-based system you are using, but I would be *astonished* 
if it didn't support the mysql package appropriate for your version of 
Python. Installing things by hand, as you appear to have done, is not 
needed.


Some further comments about the quality of advice you appear to have 
been given:

> 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')

I don't know who "some people" are, but that's clearly wrong. 
site-packages will be automatically installed in the path (unless 
something has gone horribly, horribly wrong!). And, you don't need to 
add the package itself (mysql in this case) to the path. Well, you can, 
but it goes against the concept of a self-contained package. It's 
certainly not the right way to fix the problem.



> 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)

Absolutely not. Again, there are thousands of users of mysql. If 
submodules couldn't be imported, surely they would have noticed, and the 
mysql package fixed.

Having to hack a buggy package in that way might be a reasonable 
suggestion for some sort of minor, half-debugged and slightly dodgy 
library with one maintainer and three users, but certainly not for 
something as widely-used as mysql.

 
> 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

As I mentioned above, this dot notation is not supported by 
Python 2.4. But you've installed the package into the 2.4 site-packages. 
If you ever run Python 2.4, this could cause problems for you.


Good luck!


-- 
Steve
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to