473,573 Members | 2,889 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3442
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:

ActivePytho n 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
2093
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. I am using egenenix 2.0.4 and MySQLdb 0.9.2. I have also replaced the -shared flag in the Makefile is /usr/local/lib/Python2.1/config with -G (a...
2
5038
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, sometimes not. From mysql: mysql> show databases; +-----------+ | Database |
21
5231
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 works as expected. But >>> numb=10 >>> cursor.execute("SELECT * FROM mytest where clientID = %d",numb) Traceback (innermost last): File...
2
2183
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 ------------------------------- #!/usr/bin/python import MySQLdb db = MySQLdb.connect(host="localhost", user="root", passwd="mypass", db="my_db")...
2
4499
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. Here is a sample error: >>> c=MySQLdb.Connect(host='localhost',user='root',passwd='',db='shop',port=3306) Traceback (most recent call last):
1
2204
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 = MySQLdb.connect(host='localhost', user='root', passwd='123456', db='profile_locale') c = conn.cursor(MySQLdb.cursors.DictCursor) c.execute("SET CHARACTER SET...
4
2091
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 Python version is 2.4.2. When I import MySQLdb, I get an error which says that __pure_virtual is an undefined symbol. Look:
2
4075
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 os.system('clear') try: conn = MySQLdb.connect (host = "localhost",
0
314
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 make them immediately available within the package namespace (which is why, for example, you can access os.path.* when you have imported os) and others...
0
7755
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7679
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7992
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8190
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6385
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3722
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2183
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1284
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1027
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.