当前位置:  开发笔记 > 编程语言 > 正文

Python MySQL错误的架构错误

如何解决《PythonMySQL错误的架构错误》经验,为你挑选了2个好方法。

我已经有一段时间了,并阅读了很多关于这个主题的网站.怀疑我有垃圾说谎导致这个问题.但是哪里?

这是我在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 "", line 1, in 
      File "MySQLdb/__init__.py", line 19, in 
        import _mysql
      File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in 
      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,以便它无法尝试选择它.

UPDATE

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

但基本上仍然得到相同的错误

Traceback (most recent call last):
  File "", line 1, in 
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/__init__.py", line 19, in 
    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
>>> 

小智.. 29

我有一台新的MacBook Air,我通过以下方式设法让MySQLdb工作:( Snow Leopard 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

保存后,在终端中键入以下内容:source~/.profile

下载MySQL-python-1.2.3.tar.gz unzip,untar,cd到该目录

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

退出该目录(或者你会收到警告)

python2.5
import MySQLdb

要么

python
import MySQLdb

它的工作方式应该是!!



1> 小智..:

我有一台新的MacBook Air,我通过以下方式设法让MySQLdb工作:( Snow Leopard 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

保存后,在终端中键入以下内容:source~/.profile

下载MySQL-python-1.2.3.tar.gz unzip,untar,cd到该目录

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

退出该目录(或者你会收到警告)

python2.5
import MySQLdb

要么

python
import MySQLdb

它的工作方式应该是!!



2> DS...:

尽管有很多答案,我只是在努力与之相同,所以我冒险添加另一个:

python -c 'import platform; print platform.platform()'.它以"64位"结尾吗?

ls -l /usr/local/mysql.这是一个符号链接:它以"x86_64"结尾吗?

如果python说"64位",那么你想要mysql为"x86_64"(在http://dev.mysql.com/downloads/mysql/上搜索).如果python说"32位",那么你可能想要"x86"mysql.如果你有匹配,但它仍然不起作用,那么请阅读其他答案(关于VERSIONER_PYTHON_PREFER_32_BIT等)

对我来说,不匹配导致"mach-o, but wrong architecture"错误.下一个错误是"Library not loaded: libmysqlclient.18.dylib... Reason: image not found".

要解决这个问题,我建议添加符号链接(而不是设置DYLD_LIBRARY_PATH,如其他答案中所述):

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/

推荐阅读
殉情放开那只小兔子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有