Re: [Tutor] ImportError: No module named connect

2015-11-03 Thread Steven D'Aprano
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


Re: [Tutor] ImportError: No module named connect

2015-11-03 Thread Tommy Peterson
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: stpete...@hotmail.com
To: tutor@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. 

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