473,322 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 3423
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dave Harrison | last post by:
Hi all, got a problem combinging mx and MySQLdb, when I build and install both for my Python2.1 install on a Solaris 9 box I can import mx fine, but importing MySQLdb causing python to core dump. ...
2
by: Tim Williams | last post by:
I'm trying to write a simple python program to access a MySQL database. I'm having a problem with using MySQLdb to get the results of a SQL command in a cursor. Sometimes the cursor.execute works,...
21
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All...
2
by: ws Wang | last post by:
MySQLdb is working fine at command line, however when I tried to use it with mod_python, it give me a "server not initialized" error. This is working fine: ----------------------- testmy.py...
2
by: Mondal | last post by:
Hi, I am using MySQL 5.0 beta and Active Python 2.4. I have the correct version of MySQLdb installed. The problem is that I can't connect to MySQL through the Active Python interactive window. ...
1
by: Grzegorz Smith | last post by:
Hi all. I'm trying get data from text field in MySQl 5.0 with my National characters. Data are stored in utf8 encodings. Here is the script: import MySQLdb, MySQLdb.cursors conn =...
4
by: antonyliu2002 | last post by:
I downloaded MySQL-python-1.2.1 from SourceForge and installed it on a Mandrake system (Mandrake Linux 9.2 3.3.1-2mdk on linux2). The installation was successful. The gcc version is 3.3. My...
2
rhitam30111985
by: rhitam30111985 | last post by:
hi all .. consider the following code: i basically need to build a table in the mysql database with two fields , country and office list... import MySQLdb import sys import os ...
0
by: Steve Holden | last post by:
Vaibhav.bhawsar wrote: imported The point here is that MySQLdb is a package, not a module. Some packages have their top-level __init__.py import the package's sub-modules or sub-packages to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.