Find the answer to your Linux question:
Results 1 to 8 of 8
I've just installed the MySQL python API . The only unusual thing I had to do during installation was to change the import_dirs parameter in the site.cfg config file from ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User Giles's Avatar
    Join Date
    May 2005
    Location
    Gloucestershire and Cambridge, UK
    Posts
    283

    Python & MySQL - import MySQLdb error


    I've just installed the MySQL python API. The only unusual thing I had to do during installation was to change the import_dirs parameter in the site.cfg config file from %(mysql_root)s/include to %(mysql_root)s/include/mysql (this probably wont be relevant to my problem, but I thought it was worth including).

    When I try to run
    Code:
    import _MySQLdb
    in the python environment I get the error
    Code:
    Traceback (most recent call last):
        File "<stdin>", line 1, in ?
        File "/usr/lib/python2.4/site-packages/MySQLdb/__init__.py", line 19, in ?      import _mysql
    ImportError: /usr/lib/python2.4/site-packages/_mysql.so: undefined symbol: mysql_set_character_set
    So the error crops up when __init__.py tries to import _mysql. I therefore tried to import _mysql manually, and (as you'd expect) got the same error but without the line
    File "/usr/lib/python....

    I don't really know what to try now, as this unfortunately isn't one of the import errors mentioned in the projects FAQ, and neither google or the forum search seems to have anything on this error.

    Thanks for taking the time to look at this
    Toodle-oo
    Giles
    "Our greatest fear is not that we are powerless. Our greatest fear is Microsoft"
    Registered linux user #391027

  2. #2
    Just Joined!
    Join Date
    Jul 2006
    Posts
    6

    Any solution to this ?

    Hey..

    Did you happen to get a solution to this? I am having the same issue.

    cheers,
    Nathan

    http://letstalkcoding.com

  3. #3
    Linux User Giles's Avatar
    Join Date
    May 2005
    Location
    Gloucestershire and Cambridge, UK
    Posts
    283
    More or less - a matter of a few days ago.

    In the end what seems to have worked was
    a) reinstalling slackware to clean up the system
    b) installing MySQL with some method other than from source (e.g. in my case through slapt-get)
    c) installing MySQL-python normally - it seemed to then play hapily with MySQL

    The disadvantage of this, for me, is that the slapt-get repositories dont seem to have version 5 of MySQL, so I'm stuck using version 4 at the moment.

    HTH
    Giles
    "Our greatest fear is not that we are powerless. Our greatest fear is Microsoft"
    Registered linux user #391027

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Jul 2006
    Posts
    1

    Facing same problem on linux fedora

    may i get some help how to solve this problem,
    thanks in advance

    Quote Originally Posted by Giles
    I've just installed the MySQL python API. The only unusual thing I had to do during installation was to change the import_dirs parameter in the site.cfg config file from %(mysql_root)s/include to %(mysql_root)s/include/mysql (this probably wont be relevant to my problem, but I thought it was worth including).

    When I try to run
    Code:
    import _MySQLdb
    in the python environment I get the error
    Code:
    Traceback (most recent call last):
        File "<stdin>", line 1, in ?
        File "/usr/lib/python2.4/site-packages/MySQLdb/__init__.py", line 19, in ?      import _mysql
    ImportError: /usr/lib/python2.4/site-packages/_mysql.so: undefined symbol: mysql_set_character_set
    So the error crops up when __init__.py tries to import _mysql. I therefore tried to import _mysql manually, and (as you'd expect) got the same error but without the line
    File "/usr/lib/python....

    I don't really know what to try now, as this unfortunately isn't one of the import errors mentioned in the projects FAQ, and neither google or the forum search seems to have anything on this error.

    Thanks for taking the time to look at this
    Toodle-oo
    Giles

  6. #5
    Linux User Giles's Avatar
    Join Date
    May 2005
    Location
    Gloucestershire and Cambridge, UK
    Posts
    283
    As I said above, the only way I know how to solve this is to

    1) reinstall your distro

    2) install mysql from a package (NOT from source)

    3) install MySQL-python


    If that doesn't work then you've left my area of knowledge....
    Giles
    "Our greatest fear is not that we are powerless. Our greatest fear is Microsoft"
    Registered linux user #391027

  7. #6
    Just Joined!
    Join Date
    Aug 2006
    Posts
    2
    hey guys, after smashing my head against this problem for a day, I got it working. not sure if will help anybody else, but this is what I had and how it worked:

    first, I was running on a machine with no python sources and no mysql devel installed. so, let's get those.
    1. python sources from python
    2. mysql sources from mysql (mysql5)
    3. MySQL-shared-standard-5.0.22-0.rhel4.i386.rpm (for the .so shared libraries)

    second, unpack and configure.
    1. python, just unpack in a /usr/src/redhat/SOURCES/Python2.3 folder
    1.1. create a link from /usr/include/python2.3 towards the /usr/src/redhat/SOURCES/Python-2.3.4/Include/

    2. mysql sources unpacked in the /root/downloads/mysql5 (please don't tell me to run as non root).
    2.1. run the ./configure, which will create a config.h. copy that as my_config.h in the include subdirectory (will be needed by the python driver).

    3. just rpm -i the MySQL-shared-standard-5.0.22-0.rhel4.i386.rpm. this will put in the /usr/lib the libmysqlclient libs.
    3.1. run a ldconfig so the cache gets updated.

    third. now we get to the actual driver installation.
    1. get the MySQLdb thingy, unpack it somewhere.
    2. edit the site.cfg so they point to the correct libs and headers
    example:
    ....
    [compiler]
    #mysql_root: /usr/local/mysql
    library_dirs: /usr/lib
    include_dirs: /root/downloads/mysql-5.0.22/include
    # libraries: mysqlclient
    ....

    3. do the "python setup.py build", make sure you have no error and a _mysql.so gets build in the build/lib.linux-i686-2.3 subfolder.
    4. get back to the initial folder and do the "python setup.py install" (as root). it should install it in the /usr/lib/python2.3/site-packages.
    5. test your installation "python test_MySQLdb_capabilities.py", make sure that you have a correct username and password in those tests.

    hope it works...
    ranjix

  8. #7
    Linux User Giles's Avatar
    Join Date
    May 2005
    Location
    Gloucestershire and Cambridge, UK
    Posts
    283
    Thanks for the ideas ranjix - although some elements of what you say are RH-specific, it should be translatable for other distros too. Personally I wont try that right now, as the server is very nearly ready to go live, and I've got it all working for the moment (so I dont want to risk breaking everything ), but either the next time I take it offline, or when I discover that I need a feature of MySQL 5, I'll use your ideas gladly.

    Toodle-oo
    Giles
    "Our greatest fear is not that we are powerless. Our greatest fear is Microsoft"
    Registered linux user #391027

  9. #8
    Just Joined!
    Join Date
    Aug 2006
    Posts
    2

    true, my post is related to redhat, but...

    probably instead of the RPM with the libraries you could get the targz files, unpack them and use... What do you use? Mandriva and Slackware? I don't see anything specific for those, so probably you'll use one of the non-rpm packages for generic linux or you could install an rpm program for your linux and use it.

    check out
    http://www.die.net/doc/linux/HOWTO/m...Slackware.html or
    http://club.mandriva.com/xwiki/bin/KB/MandrivaRpmHowTo

    frankly not sure how well they work. All you need from that rpm is just the libmysqlclient... so files.

Posting Permissions

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