简体   繁体   English

在Mac OS X上为Python导入MySQLdb时出错

[英]Error importing MySQLdb for Python on Mac OS X

I've spent what feels like forever running down MySQL blogs and SO questions trying to figure out how to install a MySQL server and MySQLdb for Python on my Mac OS 10.6.7. 我已经花了很多时间在MySQL博客上跑来跑去,并一直想找出如何在Mac OS 10.6.7上为Python安装MySQL服务器和MySQLdb的问题。 I think I got the MySQL server installed through MacPorts(which took an eternity), but I can't import MySQLdb ( downloaded from here ) with Python. 我想我通过MacPorts安装了MySQL服务器(这花了很长时间),但是我无法使用Python导入MySQLdb( 从此处下载 )。

Here's the error I get: 这是我得到的错误:

import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/EPD64.framework/Versions/6.3/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.5-x86_64.egg/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Frameworks/EPD64.framework/Versions/6.3/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.5-x86_64.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Frameworks/EPD64.framework/Versions/6.3/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.5-x86_64.egg/_mysql.so
Reason: image not found

I followed the instructions on this question for cleaning up and reinstalling my MySQLdb installation. 我按照有关此问题的说明清理并重新安装了MySQLdb安装。 Everything worked fine going through the steps, but it resulted in the same error. 通过这些步骤,一切正常,但是导致了相同的错误。

I'm also not sure why it's calling the EPD64.framework directory -- the module folder and contents are actually contained in /Library/Frameworks/Python.Framework/.../site-packages. 我也不确定为什么要调用EPD64.framework目录-模块文件夹和内容实际上包含在/Library/Frameworks/Python.Framework/.../site-packages中。 Could MacPorts have crossed the wires somewhere? MacPorts可以在某处越过电线吗?

(I did one extra step of modifying the msyql_config path in site.cfg to /user/local/mysql/bin/mysql_config) (我做了一个额外的步骤,将site.cfg中的msyql_config路径修改为/ user / local / mysql / bin / mysql_config)

I also tried to follow the advice of this question but can't find the /User/$User/.python-eggs directory at all, so not sure what to do about that. 我也尝试遵循此问题的建议,但根本找不到/User/$User/.python-eggs目录,因此不确定该怎么做。

Any ideas? 有任何想法吗?

The second link in your question kind of contains the answer, but there is so much extra information mucked in that's unnecessary... 您问题中的第二个链接包含答案,但是有太多多余的信息是不必要的...

Simply make sure you have the following bin: /usr/local/mysql/bin/mysql_config 只需确保您具有以下bin: /usr/local/mysql/bin/mysql_config

And then when installing MySQLdb all you need to do is change mysql_config.path in setup_posix.py to: 然后安装MySQLdb的时,所有你需要做的是改变mysql_config.pathsetup_posix.py到:

mysql_config.path = "/usr/local/mysql/bin/mysql_config"

Try simply doing that, don't do the symlinks they suggest or clean the eggs etc. 尝试简单地这样做,不要执行它们建议的符号链接或清洗鸡蛋等。

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

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