在 Mac 上安装 MySQL 以与 Python 一起使用

发布于 2024-10-08 14:07:04 字数 1577 浏览 0 评论 0原文

我只想在我的 Mac 上安装 MySQL (运行 Mac OS X 10.6.5 (Snow Leopard)) 用于 Python。

到目前为止,我已经:

  1. 下载并安装了[mysql-5.5.8-osx10.6-x86_64.dmg]。 (我也无意中下载并安装了[mysql-5.1.54-osx10.6-x86_64.dmg])

  2. 下载并安装了[mySQL-python-1.2.3]

  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:

  1. 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])

  2. Downloaded and installed [mySQL-python-1.2.3]

  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=20719

Error: 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.log

Error: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陪你到最终 2024-10-15 14:07:04

当然,您完全可以自己完成这一切。但其中有很多部分,尤其是在 OS X 10.6 及其偏爱在 64 位下运行的情况下,很难让一切都正确。我们可以一路调试每一步;为此,您需要提供更多信息。或者,您可以帮自己一个忙,从第 3 方包管理器安装所有内容,例如 MacPorts、Fink 或 Homebrew。如果您要安装更多软件包,这就更有意义了。我碰巧更喜欢 MacPorts。如果您尚未安装其基本文件,请按照此处的说明进行操作。如果您已经安装了它,请执行以下操作以确保端口列表是最新的:

$ sudo port selfupdate

然后您可以使用一个命令安装您需要的所有内容:

$ sudo port install py26-mysql

完成后:

$ /opt/local/bin/python2.6 -c "import MySQLdb; print(MySQLdb.version_info)"
(1, 2, 3, 'final', 0)

更新: 根据您提供的附加信息,它最近对 OS X 10.6 上的 Java 发行版所做的更改似乎导致依赖库之一 db46 失败。最简单的方法应该是添加一个命令来选择其非 Java 变体:

$ sudo port clean db46
$ sudo port install db46 +no_java
$ sudo port install py26-mysql

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, or Homebrew. That makes even more sense if you are going to be installing more packages. I happen to prefer MacPorts. 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:

$ sudo port selfupdate

Then you can install everything you need with one command:

$ sudo port install py26-mysql

When it's done:

$ /opt/local/bin/python2.6 -c "import MySQLdb; print(MySQLdb.version_info)"
(1, 2, 3, 'final', 0)

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:

$ sudo port clean db46
$ sudo port install db46 +no_java
$ sudo port install py26-mysql
如梦亦如幻 2024-10-15 14:07:04

import MySQLdb

对我有用(情况不同)。
否则,请确保egg已正确安装(例如在/Library/Python/2.6/site-packages/MySQL_python中)

This

import MySQLdb

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)

∞琼窗梦回ˉ 2024-10-15 14:07:04

我很幸运地使用了 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文