468,132 Members | 1,540 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,132 developers. It's quick & easy.

MySQLdb will only import for root

Hi,

I am running Python and MySQL on Ubuntu and have installed MySQLdb. If I
try to import MySQLdb I get the following error:

ActivePython 2.5.2.2 (ActiveState Software Inc.) based on
Python 2.5.2 (r252:60911, Mar 27 2008, 16:42:08)
[GCC 3.3.1 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb

But if I lrun python as the root user it imports fine. Can anyone
suggest what might be wrong with the installation? Or is there nothing
wrong? I haven't seen any examples that mentioned being root to import a
module.

Martin
Jul 11 '08 #1
8 3199
martinnorth schrieb:
Hi,

I am running Python and MySQL on Ubuntu and have installed MySQLdb. If I
try to import MySQLdb I get the following error:

ActivePython 2.5.2.2 (ActiveState Software Inc.) based on
Python 2.5.2 (r252:60911, Mar 27 2008, 16:42:08)
[GCC 3.3.1 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb

But if I lrun python as the root user it imports fine. Can anyone
suggest what might be wrong with the installation? Or is there nothing
wrong? I haven't seen any examples that mentioned being root to import a
module.
Try importing sys and printing out sys.path both with a "normal" account
and the root-account, to see if there are any differences. And of course
make sure both actually use the same interpreter.

Beyond that, you are right: there is no root-only-importing.

Diez
Jul 11 '08 #2
Is it possible the module was installed with priviledges set too
strict? Perhaps the interpreter cannot see the module when it is run
from a normal user account.
Jul 11 '08 #3
martinnorth wrote:
Hi,

I am running Python and MySQL on Ubuntu and have installed MySQLdb. If I
try to import MySQLdb I get the following error:

ActivePython 2.5.2.2 (ActiveState Software Inc.) based on
Python 2.5.2 (r252:60911, Mar 27 2008, 16:42:08)
[GCC 3.3.1 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb

But if I lrun python as the root user it imports fine. Can anyone
suggest what might be wrong with the installation? Or is there nothing
wrong? I haven't seen any examples that mentioned being root to import a
module.
You have probably installed two versions of Python. You can verify that by
typing

$ which python

and

$ sudo which python

I suspect that root sees the python that comes with Ubuntu and that has
MySQLdb installed while the normal user sees ActiveState's Python.

Peter

Jul 11 '08 #4
Jeff schrieb:
Is it possible the module was installed with priviledges set too
strict? Perhaps the interpreter cannot see the module when it is run
from a normal user account.
Possible - certainly. Yet unrealistic, because usually root access is
*required* to system-wide install a package - thus the normal install
processes ensure proper rights.

Diez
Jul 11 '08 #5
Diez B. Roggisch wrote:
>Is it possible the module was installed with priviledges set too
strict? ¬*Perhaps the interpreter cannot see the module when it is run
from a normal user account.

Possible - certainly. Yet unrealistic, because usually root access is
required to system-wide install a package - thus the normal install
processes ensure proper rights.
According to the OP, it is root that *does* have access to MySQLdb and a
normal user that does not. It is a very realistic possibility to install
something as root to which normal users do not have access. Installation
scripts that assume a particular umask during install, for example, are
especial culprits.

I have noticed this problem myself with python modules that include compiled
C extensions, as MySQLdb does. However, in the case where the extension
module itself has incorrect permissions, the error would point to a missing
_mysql, rather than a missing MySQLdb.
Jeffrey
Jul 11 '08 #6
Diez B. Roggisch wrote:
martinnorth schrieb:
>Hi,

I am running Python and MySQL on Ubuntu and have installed MySQLdb. If
I try to import MySQLdb I get the following error:

ActivePython 2.5.2.2 (ActiveState Software Inc.) based on
Python 2.5.2 (r252:60911, Mar 27 2008, 16:42:08)
[GCC 3.3.1 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
> >>import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb

But if I lrun python as the root user it imports fine. Can anyone
suggest what might be wrong with the installation? Or is there nothing
wrong? I haven't seen any examples that mentioned being root to import
a module.

Try importing sys and printing out sys.path both with a "normal" account
and the root-account, to see if there are any differences. And of course
make sure both actually use the same interpreter.

Beyond that, you are right: there is no root-only-importing.

Diez
Now that I look at, it appears it might not be the same interpreter.
When running python as root I get:

Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Which is completely different from when I'm a normal user (see original
post). And yes, sys.path is different.

Being somewhat new to python and linux, how would I go about fixing
this? How do I get a normal user to run the same interpreter? Is it to
do with my PATH?

Martin
Jul 12 '08 #7
martinnorth wrote:
Diez B. Roggisch wrote:
>martinnorth schrieb:
>>Hi,

I am running Python and MySQL on Ubuntu and have installed MySQLdb. If
I try to import MySQLdb I get the following error:

ActivePython 2.5.2.2 (ActiveState Software Inc.) based on
Python 2.5.2 (r252:60911, Mar 27 2008, 16:42:08)
[GCC 3.3.1 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb

But if I lrun python as the root user it imports fine. Can anyone
suggest what might be wrong with the installation? Or is there nothing
wrong? I haven't seen any examples that mentioned being root to import
a module.

Try importing sys and printing out sys.path both with a "normal" account
and the root-account, to see if there are any differences. And of course
make sure both actually use the same interpreter.

Beyond that, you are right: there is no root-only-importing.

Diez

Now that I look at, it appears it might not be the same interpreter.
When running python as root I get:

Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Which is completely different from when I'm a normal user (see original
post). And yes, sys.path is different.

Being somewhat new to python and linux, how would I go about fixing
this? How do I get a normal user to run the same interpreter? Is it to
do with my PATH?
Yes, you can either invoke the standard interpreter explicitly with

$ /usr/bin/python

or remove /the/path/to/activestate/python

from your PATH. (If you were just experimenting and don't really need
ActiveState I recommend that you remove it completely)

Peter

Jul 12 '08 #8
Peter Otten wrote:
martinnorth wrote:
>Hi,

I am running Python and MySQL on Ubuntu and have installed MySQLdb. If I
try to import MySQLdb I get the following error:

ActivePython 2.5.2.2 (ActiveState Software Inc.) based on
Python 2.5.2 (r252:60911, Mar 27 2008, 16:42:08)
[GCC 3.3.1 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
> >>import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb

But if I lrun python as the root user it imports fine. Can anyone
suggest what might be wrong with the installation? Or is there nothing
wrong? I haven't seen any examples that mentioned being root to import a
module.

You have probably installed two versions of Python. You can verify that by
typing

$ which python

and

$ sudo which python

I suspect that root sees the python that comes with Ubuntu and that has
MySQLdb installed while the normal user sees ActiveState's Python.

Peter
Thanks Peter, that was it. Located the ActiveState directory and removed
it. Now the module imports for all users.

Martin
Jul 12 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dave Harrison | last post: by
21 posts views Thread by John Fabiani | last post: by
2 posts views Thread by ws Wang | last post: by
2 posts views Thread by Mondal | last post: by
1 post views Thread by Grzegorz Smith | last post: by
4 posts views Thread by antonyliu2002 | last post: by
reply views Thread by Steve Holden | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.