mysql-python installation problems (on mac os x lion)

前端 未结 5 1962
渐次进展
渐次进展 2020-11-29 05:51

I installed everything successfully, or so I thought:

  • MySQL 5.5 for x86_64.
  • Python 2.7, x86_64.
  • mysql-python 1.2.3, x86_64.

Bu

相关标签:
5条回答
  • 2020-11-29 06:02

    I think there might be slight quirks with doing this on Mac 64-bit (and if you google this problem shows up a lot too).

    I've run into it, and there are a couple things you can do:

    Override the environment

    You can change the DYLD_LIBRARY_PATH environment variable, which tells the linker where to look for dynamic libraries (.so files and such). You said you also downloaded the 64-bit version of MySQL, so where ever it's installed, change the path you see here:

    In a shell:

    export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

    And then run python and see if you can import MySQLdb.

    If that works, you can make this permanent by altering your shell profile (.bash_profile, most likely).

    Use homebrew

    I don't really like mucking around with making sure MySQL and Python and all that are correct architectures and installing them separately. I run homebrew, which is a sort of package manager for Mac. If you install that, you can pretty easily take care of this issue:

    • brew install python
    • brew install mysql
    • /usr/local/share/python/easy_install mysql-python

    Do note that homebrew installs into /usr/local, so you should add /usr/local/bin to your PATH, ahead of /usr/bin and /bin, otherwise you'll get really confused why python is different.

    You can add /usr/local/share/python to your PATH as well, to make it permanent.

    0 讨论(0)
  • 2020-11-29 06:07

    Also make sure you are running Python 64-bit too. I was running mysql 64 bit and Python 32bit so got the 'but wrong architecture' error

    0 讨论(0)
  • 2020-11-29 06:11

    With the help of the comment from @birryree I found the problem. I would probably be better off following the procedure suggested by @birryree in his answer but I did try this before and it worked:

    As suggested, I did:

    file /Users/aj/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-ix86_64.egg-tmp/_mysql.so
    

    To get: [...]: Mach-O bundle i386 So, wrong architecture. From there I did the same with mysql and python just to be sure: file $(which python) gave:

    /Library/Frameworks/Python.framework/Versions/2.7/bin/python: Mach-O universal binary with 2 architectures
    /Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture i386):   Mach-O executable i386
    /Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
    

    And file $(which mysql):

    /usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
    

    So I uninstalled the mysql-python package: sudo pip uninstall mysql-python and installed it again. But doing this I realized my previous mistake while installing this package. First time I typed:

    sudo ARCHFLAGS='-arch ix86_64' python setup.py build (and "install" afterwards)

    The architecture name was wrong, should be '-arch x86_64', no "i", so it just ignored my flag and installed the 32bit.

    The proper commands to install the downloaded mysql-python package for 64bit (from the source folder):

    sudo ARCHFLAGS='-arch x86_64' python setup.py build
    sudo ARCHFLAGS='-arch x86_64' python setup.py install
    
    0 讨论(0)
  • 2020-11-29 06:12

    VERY IMPORTANT!

    As mentioned above, please make sure you are running the 64-bit version of mysql. It's easy to overlook this detail especially if you've upgraded from Snow Leopard. (I certainly did).

    if you're not sure about removing the older version of mysql on your system, refer to this post: http://johnmcostaiii.net/2011/removing-mysql-osx-lion/

    0 讨论(0)
  • 2020-11-29 06:23

    I had the same problem, and a lot of headache with MySQLdb after fixing the 64bit issue (it was complaining also about where is libmysqlclient.18.dylib).

    I think it's time to switch to the official MysQL Python Connector?

    sudo pip install mysql-connector-python
    

    Or download it from: http://dev.mysql.com/downloads/connector/python/

    Documentation: http://dev.mysql.com/doc/refman/5.5/en/connector-python.htm

    It's easy to use and also compatible with PEP 249 (Python DB API version 2.0).

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