让我花了几天时间让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医生在尝试使用--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站点,我不明白如何直接安装通用。
更新2
此页面很有用:Error importing MySQLdb in Python 2.7.2 on Mac OSx 10.8.1
所以没有 - 通用再次安装mysql并检查了这样的所有内容的架构:
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
>>>
答案 0 :(得分:1)
这是known Bug - mysql-python包目前仅针对64位构建。
答案 1 :(得分:0)
尝试使用通用标志安装mysql以避免架构二进制不匹配。我会完全卸载所有相关软件,然后清理所有相关软件的安装。
brew install mysql --universal
答案 2 :(得分:0)
可能是一个解决方法而不是解决你的问题,但如果你有一台旧的笔记本电脑/电脑,请在它上面安装一个轻型Linux发行版并将其设置为你的sql数据库服务器。
这就是我设置开发环境的方式,所以它们通过网络通信引起的轻微延迟反映出“真实世界”的连接。