在 Mac 上安装 MySQL 以与 Python 一起使用
我只想在我的 Mac 上安装 MySQL (运行 Mac OS X 10.6.5 (Snow Leopard)) 用于 Python。
到目前为止,我已经:
下载并安装了[mysql-5.5.8-osx10.6-x86_64.dmg]。 (我也无意中下载并安装了[mysql-5.1.54-osx10.6-x86_64.dmg])
下载并安装了[mySQL-python-1.2.3]
将以下内容添加到我的 .bash_profile 中:
[导出 PATH=$PATH:/usr/local/mysql/bin]
但是当我在终端中运行:import mySQLdb
时,我遇到了以下消息:
回溯(最近一次调用最后一次):
文件“”,第 1 行,在 中
导入错误:没有名为 mySQLdb 的模块
如何解决此问题?
更新: 好的,所以我尝试了 MacPorts 安装,但仍然无法正常工作。我收到以下错误消息...
错误:db46 需要 Java for Mac OS X 开发标头。
错误:从以下位置下载 Java 开发人员包:https: //connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?bundleID=20719
错误:目标 org.macports.configure 返回:缺少 Java 标头
错误:无法安装 db46
db46 的日志位于:/opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_databases_db46/main.log
错误:未安装以下依赖项:py26-distribute python26 db46 gdbm gettext expat libiconv gperf sqlite3
错误:处理期间遇到状态 1。
这对我来说意义不大,尽管我猜倒数第二个解释了为什么 Python 不在它应该在的地方。
I simply want to install MySQL on my Mac (running Mac OS X 10.6.5 (Snow Leopard)) for use with Python.
So far I have:
Downloaded and installed [mysql-5.5.8-osx10.6-x86_64.dmg]. (I have also accidentally downloaded and installed [mysql-5.1.54-osx10.6-x86_64.dmg])
Downloaded and installed [mySQL-python-1.2.3]
Added the following to my .bash_profile:
[export PATH=$PATH:/usr/local/mysql/bin]
But when I run:import mySQLdb
in terminal, I am met with the following message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mySQLdb
How can I fix this problem?
UPDATE:
Okay, so I tried the MacPorts install, but still it is not working. I got the following error messages...
Error: db46 requires the Java for Mac OS X development headers.
Error: Download the Java Developer Package from: https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?bundleID=20719Error: Target org.macports.configure returned: missing Java headers
Error: Failed to install db46
Log for db46 is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_databases_db46/main.logError: The following dependencies were not installed: py26-distribute python26 db46 gdbm gettext expat libiconv gperf sqlite3
Error: Status 1 encountered during processing.
It doesn't mean much to me, though I'm guessing the second-to-last one explains why Python is not where it should be.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当然,您完全可以自己完成这一切。但其中有很多部分,尤其是在 OS X 10.6 及其偏爱在 64 位下运行的情况下,很难让一切都正确。我们可以一路调试每一步;为此,您需要提供更多信息。或者,您可以帮自己一个忙,从第 3 方包管理器安装所有内容,例如 MacPorts、Fink 或 Homebrew。如果您要安装更多软件包,这就更有意义了。我碰巧更喜欢
MacPorts
。如果您尚未安装其基本文件,请按照此处的说明进行操作。如果您已经安装了它,请执行以下操作以确保端口列表是最新的:然后您可以使用一个命令安装您需要的所有内容:
完成后:
更新: 根据您提供的附加信息,它最近对 OS X 10.6 上的 Java 发行版所做的更改似乎导致依赖库之一 db46 失败。最简单的方法应该是添加一个命令来选择其非 Java 变体:
It is certainly possible to make it all work by yourself. But there are a lot of pieces and, especially on OS X 10.6 and its preference for running in 64-bit, it can be difficult to get everything right. We could debug each step along the way; to do that you are going to need to supply more information. Or you could do yourself a favor and install everything from a 3rd-party package manager, like
MacPorts
,Fink
, orHomebrew
. That makes even more sense if you are going to be installing more packages. I happen to preferMacPorts
. If you haven't already installed its base files, follow the instructions here. If you have installed it already, then do this to make sure the list of ports is up-to-date:Then you can install everything you need with one command:
When it's done:
Update: based on the additional information you supplied, it appears that a recent change to the Java distribution on OS X 10.6 causes one of the dependent libraries, db46, to fail. The easiest way around that should be to add a command to select its non-Java variant:
这
对我有用(情况不同)。
否则,请确保egg已正确安装(例如在/Library/Python/2.6/site-packages/MySQL_python中)
This
works for me (case is different).
Otherwise, make sure the egg is properly installed (e.g. in /Library/Python/2.6/site-packages/MySQL_python)
我很幸运地使用了 MAMP,而不是使用 Snow Leopard 将 MySQL 和 Python 直接安装到我的 Mac 上。我听说过一些恐怖故事,当您运行 Apple 的某些更新时,定制的 MySQL 和 Python 安装就会崩溃。而且能够在不需要时轻松禁用 Apache、MySQL、PHP 和 Python 在后台运行,这就是我选择 MAMP 的原因。
此网页上的第 8 部分将引导您完成如何设置 Python:
http://www.sitepen.com/blog/2008/05/ 16/supercharge-mamp/
有关 MAMP 的更多信息可以在此处找到:
http://www.mamp.info/en/mamp/index.html
I have had great luck using MAMP instead of installing MySQL and Python directly onto my Mac with Snow Leopard. I have heard horror stories of customized MySQL and Python installations breaking when you run certain updates from Apple. That, and the ability to easily disable Apache, MySQL, PHP and Python from running in the background while not needed is why I went with MAMP.
Number 8 on this webpage walks you through how to get Python setup:
http://www.sitepen.com/blog/2008/05/16/supercharge-mamp/
More information on MAMP can be found here:
http://www.mamp.info/en/mamp/index.html