简体   繁体   English

mysql-python安装问题(在ma​​c os x lion上)

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

I installed everything successfully, or so I thought: 我成功安装了所有东西,或者我认为:

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

But when I try: 但是当我尝试:

import MySQLdb

I get: 我明白了:

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

What else can I be missing? 我还能错过什么?

My system is of course 64bit version as well, uname -a gives: 我的系统当然也是64位版本, uname -a给出:

Darwin ajmacbook.local 11.1.0 Darwin Kernel Version 11.1.0: Tue Jul 26 16:07:11 PDT 2011; root:xnu-1699.22.81~1/RELEASE_X86_64 x86_64

I think I have read most SO answers and Google results on the subject, can't think of anything else to try. 我想我已经阅读了大部分关于这个主题的SO答案和谷歌搜索结果,想不出其他任何想法。 Any suggestion would be appreciated. 任何建议将不胜感激。

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). 我认为在Mac 64位上执行此操作可能会有轻微的怪癖(如果你谷歌这个问题也出现了很多)。

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). 您可以更改DYLD_LIBRARY_PATH环境变量,该变量告诉链接器在哪里查找动态库(.so文件等)。 You said you also downloaded the 64-bit version of MySQL, so where ever it's installed, change the path you see here: 你说你也下载了64位版本的MySQL,所以无论安装在哪里,都要改变你在这里看到的路径:

In a shell: 在一个shell中:

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

And then run python and see if you can import MySQLdb . 然后运行python并查看是否可以import MySQLdb

If that works, you can make this permanent by altering your shell profile ( .bash_profile , most likely). 如果可行,您可以通过更改shell配置文件( .bash_profile ,最有可能)来使其永久化。

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. 我真的不喜欢确保MySQL和Python以及所有这些都是正确的架构并单独安装它们。 I run homebrew , which is a sort of package manager for Mac. 我运行homebrew ,这是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. 请注意,自制软件安装到/usr/local ,所以你应该在/usr/bin/bin之前将/usr/local/bin到你的PATH ,否则你会为python的不同而感到困惑。

You can add /usr/local/share/python to your PATH as well, to make it permanent. 您也可以将/usr/local/share/pythonPATH中,以使其永久化。

With the help of the comment from @birryree I found the problem. 在@birryree的评论的帮助下,我发现了问题。 I would probably be better off following the procedure suggested by @birryree in his answer but I did try this before and it worked: 我可能会更好地遵循@birryree在他的回答中建议的程序,但我之前尝试过这个并且它有效:

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. 得到: [...]: Mach-O bundle i386所以,错误的架构。 From there I did the same with mysql and python just to be sure: file $(which python) gave: 从那里我做了相同的mysql和python只是为了确定: file $(which python)给出:

/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) : 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. 所以我卸载了mysql-python包: sudo pip uninstall mysql-python并再次安装它。 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) sudo ARCHFLAGS='-arch ix86_64' python setup.py build (以及之后的“install”)

The architecture name was wrong, should be '-arch x86_64', no "i", so it just ignored my flag and installed the 32bit. 架构名称错误,应该是'-arch x86_64',没有“i”,所以它只是忽略了我的旗帜并安装了32位。

The proper commands to install the downloaded mysql-python package for 64bit (from the source folder): 安装下载的64位mysql-python包的正确命令(来自源文件夹):

sudo ARCHFLAGS='-arch x86_64' python setup.py build
sudo ARCHFLAGS='-arch x86_64' python setup.py install

VERY IMPORTANT! 很重要!

As mentioned above, please make sure you are running the 64-bit version of mysql. 如上所述,请确保您运行的是64位版本的mysql。 It's easy to overlook this detail especially if you've upgraded from Snow Leopard. 如果您从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/ 如果您不确定在系统上删除旧版本的mysql,请参阅以下文章: http//johnmcostaiii.net/2011/removing-mysql-osx-lion/

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). 我遇到了同样的问题,在修复64位问题后,MySQLdb很头疼(它还抱怨libmysqlclient.18.dylib在哪里)。

I think it's time to switch to the official MysQL Python Connector? 我认为是时候切换到官方的MysQL Python连接器了?

sudo pip install mysql-connector-python

Or download it from: http://dev.mysql.com/downloads/connector/python/ 或者从以下网址下载: http//dev.mysql.com/downloads/connector/python/

Documentation: http://dev.mysql.com/doc/refman/5.5/en/connector-python.htm 文档: 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). 它易于使用,并且与PEP 249(Python DB API 2.0版)兼容。

Also make sure you are running Python 64-bit too. 还要确保您也在运行Python 64位 I was running mysql 64 bit and Python 32bit so got the 'but wrong architecture' error 我运行mysql 64位和Python 32位所以得到了'但错误的架构'错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM