Re: MySQLdb will only import for root

Discussion in 'Python' started by Diez B. Roggisch, Jul 11, 2008.

  1. 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
    Diez B. Roggisch, Jul 11, 2008
    #1
    1. Advertising

  2. Diez B. Roggisch

    Jeff Guest

    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.
    Jeff, Jul 11, 2008
    #2
    1. Advertising

  3. 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
    Diez B. Roggisch, Jul 11, 2008
    #3
  4. Diez B. Roggisch

    Peter Otten Guest

    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
    Peter Otten, Jul 12, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,201
  2. Rick Osborn
    Replies:
    10
    Views:
    3,939
    Jon A. Cruz
    Feb 8, 2004
  3. Alan Little

    can't import MySQldb on OS X

    Alan Little, Jun 25, 2003, in forum: Python
    Replies:
    0
    Views:
    824
    Alan Little
    Jun 25, 2003
  4. hector
    Replies:
    5
    Views:
    398
    CBFalconer
    Dec 5, 2006
  5. Michael Boldin via alt email

    IDLE & MySQLdb import error

    Michael Boldin via alt email, Mar 4, 2007, in forum: Python
    Replies:
    0
    Views:
    548
    Michael Boldin via alt email
    Mar 4, 2007
Loading...

Share This Page