gpt4 book ai didi

Python MySQL错误架构错误

转载 作者:IT老高 更新时间:2023-10-28 22:17:45 26 4
gpt4 key购买 nike

我在这方面已经有一段时间了,并阅读了许多有关该主题的网站。怀疑我在撒谎导致这个问题。但是在哪里?

这是我在python中导入MySQLdb时的错误:

>>> import MySQLdb
/Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg/_mysql.pyc, but /Users/phoebebr/Downloads/MySQL-python-1.2.3c1 is being added to sys.path
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "MySQLdb/__init__.py", line 19, in <module>
import _mysql
File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/phoebebr/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): no suitable image found. Did find:
/Users/phoebebr/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: mach-o, but wrong architecture

我正在尝试 64 位,所以在这里检查:

file $(which python)
/usr/bin/python: Mach-O universal binary with 3 architectures
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/python (for architecture ppc7400): Mach-O executable ppc
file $(which mysql)
/usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64

已将我的默认 python 版本设置为 2.6

python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin

尝试删除构建目录和 python setup.py clean重命名了 Python/2.5/site-packages,因此它无法尝试获取它。

更新

删除所有内容并按照此处的说明进行操作:Django + MySQL on Mac OS 10.6.2 Snow Leopard使用 macports 安装。

但基本上还是报同样的错误

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/_mysql.so, 2): no suitable image found. Did find:
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/_mysql.so: mach-o, but wrong architecture
>>>

最佳答案

我有一台全新的 MacBook Air,我通过执行以下操作设法让 MySQLdb 正常工作:(雪豹10.6.6,预装Python)

uname -a
Darwin Braindamage.local 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov 10 18:13:17 PST 2010; root:xnu-1504.9.26~3/RELEASE_I386 i386

从 mysql 页面下载 MySQL 32 位 dmg 文件,安装。

将以下行添加到您的 ~/.profile(或 ~/.bash_profile)中:

PATH="/usr/local/mysql/bin:${PATH}"
export PATH
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
export VERSIONER_PYTHON_PREFER_64_BIT=no
export VERSIONER_PYTHON_PREFER_32_BIT=yes

保存后,在终端输入以下内容: 来源 ~/.profile

下载 MySQL-python-1.2.3.tar.gz 解压,untar,cd 到那个目录

python2.5 setup.py build
sudo python2.5 setup.py install

退出该目录(否则您会收到警告)

python2.5
import MySQLdb

python
import MySQLdb

按应有的方式工作!!

关于Python MySQL错误架构错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3061277/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com