Python MySQL wrong architecture error

后端 未结 12 2158

I\'ve been at this for some time and read many sites on the subject. suspect I have junk lying about causing this problem. But where?

This is the error when I impor

相关标签:
12条回答
  • 2020-12-08 05:16

    I just struggled with the same, despite the many answers, so I'll risk adding another:

    • Run python -c 'import platform; print platform.platform()'. Does it end in "64 bit"?
    • Do ls -l /usr/local/mysql. It's a symlink: does it end in "x86_64"?

    If python says "64 bit", then you want mysql for "x86_64" (search for that at http://dev.mysql.com/downloads/mysql/). If python says "32 bit", then you probably want the "x86" mysql. If you have a match, but it still doesn't work, then read the other answers (about VERSIONER_PYTHON_PREFER_32_BIT etc.)

    For me, the mismatch caused the "mach-o, but wrong architecture" error. The next error was "Library not loaded: libmysqlclient.18.dylib... Reason: image not found".

    To solve this one, I recommend adding a symlink (rather than set DYLD_LIBRARY_PATH, as explained in other answers):

    sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/
    
    0 讨论(0)
  • 2020-12-08 05:17

    When the interpreter says is:

    You have installed MySQL_python-1.2.3c1 in /Library/Python/2.6/site-packages but you are adding to sys.path another version in /users/phoebebr/Downloads. When I try to import MySQLdb from the second directory, I've found that _mysql.so is from another architecture.

    SO, it seems that you ended with the wrong version of MySQLdb. Delete /Users/phoebebr/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp and /Users/phoebebr/Downloads/MySQL-python-1.2.3c1. Test again to see if the version in /library works. If not, donwload the binary for MacOS. In last instance, download the source of MySQL-python and compile it.

    0 讨论(0)
  • 2020-12-08 05:20

    I met the same problem.

    • My situation: Mac OSX 10.6, python is 64 bit, mysql is 32 bit, and _mysql.so is 32 bit.

    • Solution: uninstall mysql (http://steveno.wordpress.com/2009/03/26/uninstall-mysql-on-mac-os-x/), and install 64 bit mysql. Then make sure mysql_config is pointed to the one you just installed.

    IMPORTANT:
    remove all the _mysql.so in the MySQL-python-1.2.3 directory (this is what you download) or just remove the whole directory and generate it again from the tar file. Then build and install again. Then _mysql.so will be 64 bit. Now you can import it. If you see dyld: Library not loaded, then export DYLD_LIBRARY_PATH=/usr/local/mysql/lib

    0 讨论(0)
  • 2020-12-08 05:24

    I got another possible solution to add.

    I solved the problem by adding the following line to .profile (.bash_profile is ok if it's a development machine):

    export VERSIONER_PYTHON_PREFER_64_BIT=yes
    export VERSIONER_PYTHON_PREFER_32_BIT=no
    

    (2nd line might not be necessary, though. But after hours of fiddling, trying, recompiling, I just couldn't be bothered trying this out anymore).

    0 讨论(0)
  • 2020-12-08 05:31

    I had the same problem with my ElCaptain Mac and solved the problem following this other post. Just use brew and your problem is solved.

    0 讨论(0)
  • 2020-12-08 05:32

    Additional note to make the problem clear:

    The error message is:

    ImportError: dlopen(/Users/phoebebr/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): no suitable image found.  Did find:
        /Users/phoebebr/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: mach-o, but wrong architecture
    

    The mach-o, but wrong architecture error means that python and _mysql.so have different architecture(32-bit/64-bit binary). We can check it by:

    file $(which python)
    file /Users/phoebebr/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
    

    And if they do not match, we should make them match. For me, my _mysql.so is 32-bit (I happened to installed the 32-bit mysql), and my python2.7 runs in 64-bit by default. I force python runs in 32-bit by:

    export VERSIONER_PYTHON_PREFER_32_BIT=yes
    

    And problem solved.

    python 2.6+ can run in 64 or 32-bit mode, check How do I determine if my python shell is executing in 32bit or 64bit mode on OS X?

    0 讨论(0)
提交回复
热议问题