4

我花了几天时间让 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 版本的正确版本 no平台,所以我没有进一步追求。)

更新

干净地运行 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
>>> 
4

3 回答 3

1

这是一个已知的错误——mysql-python 包目前仅用于 64 位。

于 2013-08-07T12:30:27.783 回答
0

可能是一种解决方法而不是解决您的问题,但是如果您有一台旧的笔记本电脑/计算机,请在其上安装一个轻型 linux 发行版并将其设置为您的 sql 数据库服务器。

无论如何,这就是我设置开发环境的方式,因此它们通过网络通信产生的轻微延迟来反映“现实世界”的连接性。

于 2015-03-25T13:07:43.787 回答
0

尝试使用通用标志安装 mysql 以避免架构二进制不匹配。我会彻底卸载所有相关软件,然后全新安装所有相关软件。

冲泡安装 mysql --universal

于 2013-08-07T17:36:23.583 回答