Confusing, desparate MySQLdb problems...

S

stopchuckingstuff

I have installed MySQLdb on Mac OSX 10.6.2, and have it working when
running on my system in IDLE and in terminal, however encounter
continual problems when running it through Apache.

When trying to import the module, it gives me this error:

<type 'exceptions.ImportError'>: /Library/WebServer/.python-eggs/
MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg-tmp/_mysql.so: no
appropriate 64-bit architecture (see "man python" for running in 32-
bit mode)

Which I just don't understand, as it works perfectly in IDLE?!

I am running Snow Leopard in 64bit mode, but I don't see how this
could be the problem when I have already run the module successfully.

Please help!

Thanks very much,
Sam
(e-mail address removed)
 
N

Ned Deily

stopchuckingstuff said:
I have installed MySQLdb on Mac OSX 10.6.2, and have it working when
running on my system in IDLE and in terminal, however encounter
continual problems when running it through Apache.

When trying to import the module, it gives me this error:

<type 'exceptions.ImportError'>: /Library/WebServer/.python-eggs/
MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg-tmp/_mysql.so: no
appropriate 64-bit architecture (see "man python" for running in 32-
bit mode)

Which I just don't understand, as it works perfectly in IDLE?!

I am running Snow Leopard in 64bit mode, but I don't see how this
could be the problem when I have already run the module successfully.

Most likely possibility: you've installed another Python on 10.6,
probably from python.org, which only runs in 32-bit mode while Apache is
using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit
mode. From the terminal, do:

which python

If it's not /usr/bin/python, you're using another Python in the
terminal. You'll need to install a 64-bit version of the MySQLdb and
the MySQL client libraries for the Apple-supplied Python or modify the
Apache setup to either force 32-bit mode for the Apple-supplied Python
or use the other Python (from /usr/local/bin/python2.6 or wherever).
 
S

stopchuckingstuff

Most likely possibility: you've installed another Python on 10.6,
probably from python.org, which only runs in 32-bit mode while Apache is
using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit
mode.  From the terminal, do:

which python

If it's not /usr/bin/python, you're using another Python in the
terminal.  You'll need to install a 64-bit version of the MySQLdb and
the MySQL client libraries for the Apple-supplied Python or modify the
Apache setup to either force 32-bit mode for the Apple-supplied Python
or use the other Python (from /usr/local/bin/python2.6 or wherever).

Thanks very much - I think this must be the problem (which python
produces some long path to Python 2.6). Ideally, I'd like to change
Apache's path to python as I had such problems installing MySQLdb -
would you have any idea how to do it?

Thanks again for you help
Sam
 
S

stopchuckingstuff

Most likely possibility: you've installed another Python on 10.6,
probably from python.org, which only runs in 32-bit mode while Apache is
using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit
mode.  From the terminal, do:

which python

If it's not /usr/bin/python, you're using another Python in the
terminal.  You'll need to install a 64-bit version of the MySQLdb and
the MySQL client libraries for the Apple-supplied Python or modify the
Apache setup to either force 32-bit mode for the Apple-supplied Python
or use the other Python (from /usr/local/bin/python2.6 or wherever).

Thanks very much - I think this must be the problem (which python
produces some long path to Python 2.6). Ideally, I'd like to change
Apache's path to python as I had such problems installing MySQLdb -
would you have any idea how to do it?

Thanks again for you help
Sam
 
S

stopchuckingstuff

Most likely possibility: you've installed another Python on 10.6,
probably from python.org, which only runs in 32-bit mode while Apache is
using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit
mode.  From the terminal, do:

which python

If it's not /usr/bin/python, you're using another Python in the
terminal.  You'll need to install a 64-bit version of the MySQLdb and
the MySQL client libraries for the Apple-supplied Python or modify the
Apache setup to either force 32-bit mode for the Apple-supplied Python
or use the other Python (from /usr/local/bin/python2.6 or wherever).

Sorry for the repeat posts, but would it be to do with the first line
of all my scripts - #!/usr/bin/env python?

Thanks
Sam
 
S

stopchuckingstuff

Most likely possibility: you've installed another Python on 10.6,
probably from python.org, which only runs in 32-bit mode while Apache is
using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit
mode.  From the terminal, do:

which python

If it's not /usr/bin/python, you're using another Python in the
terminal.  You'll need to install a 64-bit version of the MySQLdb and
the MySQL client libraries for the Apple-supplied Python or modify the
Apache setup to either force 32-bit mode for the Apple-supplied Python
or use the other Python (from /usr/local/bin/python2.6 or wherever).

Sorry for the repeat posts, but would it be to do with the first line
of all my scripts - #!/usr/bin/env python?

Thanks
Sam
 
N

Ned Deily

I have installed MySQLdb on Mac OSX 10.6.2, and have it working when
running on my system in IDLE and in terminal, however encounter
continual problems when running it through Apache.
When trying to import the module, it gives me this error:
<type 'exceptions.ImportError'>: /Library/WebServer/.python-eggs/
MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg-tmp/_mysql.so: no
appropriate 64-bit architecture (see "man python" for running in 32-
bit mode) [...]
Most likely possibility: you've installed another Python on 10.6,
probably from python.org, which only runs in 32-bit mode while Apache is
using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit
mode. [...]
Thanks very much - I think this must be the problem (which python
produces some long path to Python 2.6). Ideally, I'd like to change
Apache's path to python as I had such problems installing MySQLdb -
would you have any idea how to do it? [...]
Sorry for the repeat posts, but would it be to do with the first line
of all my scripts - #!/usr/bin/env python?

/usr/bin/env python will cause the first command named python in the
process's execution path ($PATH) to be used. Apache is probably not
running under your user name and does not have the PATH modification in
your .bash_profile to stick that long path to the python.org Python 2.6
bin directory at the front of $PATH. Rather than changing Apache's
startup, the easier solution would probably be to modify your scripts to
point at the desired python. By default, the python.org installers put
a link to that python in /usr/local/bin so it may be easier to use a
shebang line like:

#!/usr/local/bin/python
or
#!/usr/local/bin/python2.6
 
S

stopchuckingstuff

 stopchuckingstuff said:
I have installed MySQLdb on Mac OSX 10.6.2, and have it working when
running on my system in IDLE and in terminal, however encounter
continual problems when running it through Apache.
When trying to import the module, it gives me this error:
<type 'exceptions.ImportError'>: /Library/WebServer/.python-eggs/
MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg-tmp/_mysql.so: no
appropriate 64-bit architecture (see "man python" for running in 32-
bit mode) [...]
Most likely possibility: you've installed another Python on 10.6,
probably from python.org, which only runs in 32-bit mode while Apache is
using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit
mode. [...]
Thanks very much - I think this must be the problem (which python
produces some long path to Python 2.6). Ideally, I'd like to change
Apache's path to python as I had such problems installing MySQLdb -
would you have any idea how to do it? [...]
Sorry for the repeat posts, but would it be to do with the first line
of all my scripts - #!/usr/bin/env python?

/usr/bin/env python will cause the first command named python in the
process's execution path ($PATH) to be used.  Apache is probably not
running under your user name and does not have the PATH modification in
your .bash_profile to stick that long path to the python.org Python 2.6
bin directory at the front of $PATH.   Rather than changing Apache's
startup, the easier solution would probably be to modify your scripts to
point at the desired python.  By default, the python.org installers put
a link to that python in /usr/local/bin so it may be easier to use a
shebang line like:

#!/usr/local/bin/python
or
#!/usr/local/bin/python2.6

This just gets even more confusing!

I used a shebang line:

#!/Library/Frameworks/Python.framework/Versions/2.6/bin/python

which i got from which python in terminal, and now i get this error
when trying to import MySQLdb:

<type 'exceptions.ImportError'>: No module named pkg_resources

How!? I don't get that error when using that same version of python in
IDLE...

What's going on?!

Many thanks for your ongoing assistance!
Sam
 
S

stopchuckingstuff

 stopchuckingstuff said:
I have installed MySQLdb on Mac OSX 10.6.2, and have it working when
running on my system in IDLE and in terminal, however encounter
continual problems when running it through Apache.
When trying to import the module, it gives me this error:
<type 'exceptions.ImportError'>: /Library/WebServer/.python-eggs/
MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg-tmp/_mysql.so: no
appropriate 64-bit architecture (see "man python" for running in 32-
bit mode) [...]
Most likely possibility: you've installed another Python on 10.6,
probably from python.org, which only runs in 32-bit mode while Apache is
using the Apple-supplied Python 2.6.1 which, by default, runs in 64-bit
mode. [...]
Thanks very much - I think this must be the problem (which python
produces some long path to Python 2.6). Ideally, I'd like to change
Apache's path to python as I had such problems installing MySQLdb -
would you have any idea how to do it? [...]
Sorry for the repeat posts, but would it be to do with the first line
of all my scripts - #!/usr/bin/env python?

/usr/bin/env python will cause the first command named python in the
process's execution path ($PATH) to be used.  Apache is probably not
running under your user name and does not have the PATH modification in
your .bash_profile to stick that long path to the python.org Python 2.6
bin directory at the front of $PATH.   Rather than changing Apache's
startup, the easier solution would probably be to modify your scripts to
point at the desired python.  By default, the python.org installers put
a link to that python in /usr/local/bin so it may be easier to use a
shebang line like:

#!/usr/local/bin/python
or
#!/usr/local/bin/python2.6

What's even worse, is that importing pkg_resources works fine in
terminal, and the sys.paths in each are the same!?!
 
N

Ned Deily

stopchuckingstuff said:
This just gets even more confusing!

I used a shebang line:

#!/Library/Frameworks/Python.framework/Versions/2.6/bin/python

which i got from which python in terminal, and now i get this error
when trying to import MySQLdb:

<type 'exceptions.ImportError'>: No module named pkg_resources

How!? I don't get that error when using that same version of python in
IDLE...

What's going on?!

Sounds like setuptools is not being found on sys.path. And, judging
from your earlier post, it appears that sys.path when running under
Apache includes /Library/WebServer/.python-eggs. Perhaps you need to
ensure setuptools is installed there. That wouldn't normally be on the
python's sys.path when running from the terminal.

But I realized after my last response that I should have asked how you
were using Python with Apache: presumably with mod_wsgi or, possibly,
mod_python. In either case, the configurations are more complex and
something I have little experience with so I should probably point you
elsewhere. For mod_wsgi, Graham Dumpleton offers exemplary thorough
documentation here:

http://code.google.com/p/modwsgi/
http://code.google.com/p/modwsgi/wiki/InstallationOnMacOSX
http://code.google.com/p/modwsgi/wiki/WhereToGetHelp

Good luck.
 
S

stopchuckingstuff

[...]
This just gets even more confusing!
I used a shebang line:

which i got from which python in terminal, and now i get this error
when trying to import MySQLdb:
<type 'exceptions.ImportError'>: No module named pkg_resources
How!? I don't get that error when using that same version of python in
IDLE...
What's going on?!

Sounds like setuptools is not being found on sys.path.  And, judging
from your earlier post, it appears that sys.path when running under
Apache includes /Library/WebServer/.python-eggs.  Perhaps you need to
ensure setuptools is installed there.  That wouldn't normally be on the
python's sys.path when running from the terminal.

But I realized after my last response that I should have asked how you
were using Python with Apache: presumably with mod_wsgi or, possibly,
mod_python.  In either case, the configurations are more complex and
something I have little experience with so I should probably point you
elsewhere.  For mod_wsgi, Graham Dumpleton offers exemplary thorough
documentation here:

http://code.google.com/p/modwsgi/ht...code.google.com/p/modwsgi/wiki/WhereToGetHelp

Good luck.

I'm not using either mod_wsgi or mod_python, I just edited httpd.conf.

You're right about setuptools - imports in terminal, not in cgi.
however, the path to it (/Library/Frameworks/Python.framework/Versions/
2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg)
is present in both sys.paths - as i said, both sys.paths are
identical.

And from printing the sys.paths, /Library/WebServer/.python-eggs
doesn't appear, I think it just uses it as a temporary folder to unzip
the python eggs into.

What I don't understand is if the path is there, why doesn't it find
the module?

Thanks
Sam
 
N

Ned Deily

I'm not using either mod_wsgi or mod_python, I just edited httpd.conf.

You're right about setuptools - imports in terminal, not in cgi.
however, the path to it (/Library/Frameworks/Python.framework/Versions/
2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg)
is present in both sys.paths - as i said, both sys.paths are
identical.

And from printing the sys.paths, /Library/WebServer/.python-eggs
doesn't appear, I think it just uses it as a temporary folder to unzip
the python eggs into.
From your original post:
When trying to import the module, it gives me this error:

<type 'exceptions.ImportError'>: /Library/WebServer/.python-eggs/
MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg-tmp/_mysql.so: no
appropriate 64-bit architecture (see "man python" for running in 32-
bit mode)

so it appears that the .python-eggs directory is on sys.path. But I
don't know where that directory is coming from in the first place.
Something you manually created?
What I don't understand is if the path is there, why doesn't it find
the module?

Perhaps it is just a permissions problem since Apache is probably
running under a different user name. Check the owner/group and
permissions of the various module directories and files. Make sure the
directories and .so files have at least r-x and the python files at
least r-- across the board.
 
S

stopchuckingstuff

so it appears that the .python-eggs directory is on sys.path.  But I
don't know where that directory is coming from in the first place.  
Something you manually created?




Perhaps it is just a permissions problem since Apache is probably
running under a different user name.  Check the owner/group and
permissions of the various module directories and files. Make sure the
directories and .so files have at least r-x and the python files at
least r-- across the board.

Of course! how did i not realise that... it wasn't the python-eggs
directory, but the directory containing the modules (namely /Library/
Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages)
- i changed the permissions, and its all sorted!

Thank you so much!!
Sam
 
N

Ned Deily

Of course! how did i not realise that... it wasn't the python-eggs
directory, but the directory containing the modules (namely /Library/
Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages)
- i changed the permissions, and its all sorted!

Yay! Sorry, I should have thought of permissions earlier: I've been
bitten by that more than once. It's an important thing to keep in mind
when encountering missing imports: always check file system permissions
first.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top