【发布时间】:2013-07-29 09:15:09
【问题描述】:
我花了几天时间让 mysqldb 在 Snow Leopard 上工作,所以这次我完全干净地安装了操作系统,并仔细按照安装的各种说明来尝试让我的 django 开发环境正常工作。
brew install mysql
sudo pip intall django
sudo pip install mysql-python
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
export PATH=/usr/local/mysql/bin:$PATH
sudo export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
Mysql 和 django 工作正常,但如果我尝试导入 MySQLdb 或执行 syncdb,我会收到此错误:
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /Library/Python/2.7/site-packages/_mysql.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/_mysql.so
>>>
已经在谷歌上搜索了一天没有成功,真的需要回去工作了!非常欢迎任何建议。
(也尝试在此处安装 mysql python-connector http://dev.mysql.com/downloads/connector/python/ 但没有 osx 版本,其他说明似乎暗示您需要适合您的 python 版本的正确版本,因此我没有进一步追求。 )
更新
干净地运行 brew doctor 后,在尝试 --universal 选项时遇到这些错误:
iMacs-iMac:~ phoebebr$ brew install -v mysql --universal
==> Downloading http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.13.tar.gz/from/http://cdn.mysql.com/
Already downloaded: /Library/Caches/Homebrew/mysql-5.6.13.com
tar xf /Library/Caches/Homebrew/mysql-5.6.13.com
==> cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/mysql/5.6.13 -DMYSQL_DATADIR=/usr/local/var/mysql -DINSTALL_MANDIR=/usr/local/Cellar/mysql/5.6.13/share/man -DINSTALL_DOCDIR=/usr/local/Cellar/mysql/5.6.13/share/doc/mysql -DINSTALL_INFODIR=/usr/local/Cellar/mysql/5.6.13/share/info -DINSTALL_MYSQLSHAREDIR=share/mysql -DWITH_SSL=yes -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DSYSCONFDIR=/usr/local/etc -DWITH_UNIT_TESTS=OFF -DWITH_READLINE=yes -DCMAKE_OSX_ARCHITECTURES='i386;x86_64'
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/mysql/5.6.13 -DMYSQL_DATADIR=/usr/local/var/mysql -DINSTALL_MANDIR=/usr/local/Cellar/mysql/5.6.13/share/man -DINSTALL_DOCDIR=/usr/local/Cellar/mysql/5.6.13/share/doc/mysql -DINSTALL_INFODIR=/usr/local/Cellar/mysql/5.6.13/share/info -DINSTALL_MYSQLSHAREDIR=share/mysql -DWITH_SSL=yes -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DSYSCONFDIR=/usr/local/etc -DWITH_UNIT_TESTS=OFF -DWITH_READLINE=yes -DCMAKE_OSX_ARCHITECTURES='i386;x86_64'
-- Running cmake version 2.8.11.2
-- The C compiler identification is Clang 4.2.0
-- The CXX compiler identification is GNU 4.2.1
CMake Error at /usr/local/Cellar/cmake/2.8.11.2/share/cmake/Modules/Platform/Darwin.cmake:190 (message):
CMAKE_OSX_DEPLOYMENT_TARGET is '10.8' but CMAKE_OSX_SYSROOT:
""
is not set to a MacOSX SDK with a recognized version. Either set
CMAKE_OSX_SYSROOT to a valid SDK or set CMAKE_OSX_DEPLOYMENT_TARGET to
empty.
Call Stack (most recent call first):
/usr/local/Cellar/cmake/2.8.11.2/share/cmake/Modules/CMakeSystemSpecificInformation.cmake:36 (include)
CMakeLists.txt:99 (PROJECT)
-- Configuring incomplete, errors occurred!
==> Configuration
HOMEBREW_VERSION: 0.9.4
HEAD: b9b09cb1a620cd5ddafffc22d56a34e160bfc3f4
CPU: dual-core 64-bit penryn
OS X: 10.8.4-x86_64
Xcode: 4.6.3
CLT: 4.6.0.0.1.1365549073
X11: 2.7.4 => /opt/X11
==> ENV
CFLAGS: -Os -w -pipe
CXXFLAGS: -Os -w -pipe
LDFLAGS: -L/usr/local/lib
MAKEFLAGS: -j2
MACOSX_DEPLOYMENT_TARGET: 10.8
PKG_CONFIG_LIBDIR: /usr/local/lib/pkgconfig:/usr/local/Library/ENV/pkgconfig/10.8:/usr/lib/pkgconfig
OBJC: /usr/bin/clang
PATH: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/Library/Contributions/cmd
CPATH: /usr/local/include
Error: mysql did not build
Logs: /Users/phoebebr/Library/Logs/Homebrew/mysql/CMakeCache.txt
确实发现这与 cmake 错误有关,但这确实超出了我的技术能力! http://cmake.3232098.n2.nabble.com/OSX-deployment-target-confusion-for-2-8-10-td7582284.html 查看 mysql 站点,对我来说如何直接安装 Universal 并不明显。
更新 2
这个页面很有用:Error importing MySQLdb in Python 2.7.2 on Mac OSx 10.8.1
所以再次安装了mysql,没有--universal,并检查了所有东西的架构:
iMacs-iMac:~ phoebebr$ which python
/usr/bin/python
iMacs-iMac:bin phoebebr$ file /usr/bin/python
/usr/bin/python: Mach-O universal binary with 2 architectures
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
iMacs-iMac:mysql phoebebr$ which mysql
/usr/local/bin/mysql
iMacs-iMac:mysql phoebebr$ file /usr/local/bin/mysql
/usr/local/bin/mysql: Mach-O 64-bit executable x86_64
仍然出现同样的错误。
iMacs-iMac:~ phoebebr$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /Library/Python/2.7/site-packages/_mysql.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/_mysql.so
>>>
【问题讨论】:
-
然后回到我的 mac 上只有 sqlite。有人建议切换到 Postgresql,所以可能会试一试。
-
您是否检查过您的二进制文件是否针对正确的架构构建? MacOSX 保留了 i386 和 x86_64 二进制文件,有时还保留了任意组合。你试过macports吗?我尝试了自制软件,但随着时间的推移,我对它的不一致感到非常失望,所以我切换回去了。
-
由于这是一台相对较新的机器和新安装,我可以确信一切都是 64 位的。 Homebrew 知道它是 64 位的,.bash_profile 有 export ARCHFLAGS="-arch x86_64" 我还应该做些什么吗?
标签: osx-mountain-lion mysql-python