Results 1 to 6 of 6

Thread: [Python] "_mysql was already imported" error

  1. #1
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    [Python] "_mysql was already imported" error

    Can you explain what is causing this error?

    PHP Code:
    cat test.py
    #!/usr/bin/env python
    import MySQLdb
    import matplotlib
    test.py
    /usr/lib/python2.5/site-packages/pytz/__init__.py:29UserWarningModule _mysql was already imported from /var/lib/python-support/python2.5/_mysql.sobut /var/lib/python-support/python2.5 is being added to sys.path
      from pkg_resources import resource_stream 
    But if I switch the order of the imports, the error goes away:
    PHP Code:
    cat test.py
    #!/usr/bin/env python
    import matplotlib
    import MySQLdb
    test.py

    This is occurring on a fresh Intrepid install. I tried googling
    "_mysql was already imported" for an answer, but came up empty.

    PHP Code:
    apt-cache policy python-matplotlib
    python
    -matplotlib:
      
    Installed0.98.3-4ubuntu1

    apt-cache policy python-mysqldb
    python
    -mysqldb:
      
    Installed1.2.2-

  2. #2
    Join Date
    Aug 2008
    Beans
    Hidden!

    Re: [Python] "_mysql was already imported" error

    It would appear that matplotlib imports mySQLdb and that it does it in a manner that a message is issued if mySQLdb already is imported.

    If it's an issue, I'd have a look into the initialization of matplotlib, particularly into the method __init__ of the class pytz which is named in the warning message.

  3. #3
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: [Python] "_mysql was already imported" error

    Thanks, pp., but I'm still confused.

    If you have python-mysqldb and python-matplotlib installed,
    can you reproduce the same error?

    • As far as I can tell, matplotlib does not import _mysql.
      For one thing, python-matplotlib does not list mysql as a dependency.
    • Isn't it true that packages can be imported repeatedly with no adverse consequence? If so, why should pytz throw a UserWarning about this?
    • /usr/lib/python2.5/site-packages/pytz has to do with timezones.
      Is matplotlib or mysqldb importing pytz? I haven't been able to track down where this is happening.


    Thank you for your time and thought. I'd greatly appreciate any additional help you can give.

  4. #4
    Join Date
    Aug 2008
    Beans
    Hidden!

    Re: [Python] "_mysql was already imported" error

    Perhaps it would be useful to study this file, particularly line 29:

    /usr/lib/python2.5/site-packages/pytz/__init__.py:29

  5. #5
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: [Python] "_mysql was already imported" error

    I managed to make the warning go away by editing /usr/lib/python2.5/site-packages/pkg_resources.py:

    I changed line 2272:

    From:
    PHP Code:
                if fn and normalize_path(fn).startswith(loc): 
    To:
    PHP Code:
                if fn and (fn.startswith(loc) or normalize_path(fn).startswith(loc)): 
    Thanks for your help, pp.!

  6. #6
    Join Date
    Aug 2008
    Beans
    Hidden!

    Re: [Python] "_mysql was already imported" error

    Quote Originally Posted by unutbu View Post
    Thanks for your help, pp.!
    You're welcome, but I suggest to read this thread again: All I did was to selectively quote the error message to you which you included in your first post. There's a lesson somewhere hidden.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •