操作系统:
Mac os,版本:10.12.5,64bit Mysql:版本 5.7.18 Homebrew
使用 brew 安装了 mysql ( Server version: 5.7.18 Homebrew ) ,然后下载了 MySQLdb,正确安装尅没有报错,安装成功后报错,报错如下:
MySQL_python-1.2.5-py2.7.egg-info lazybone$ python -c "import MySQLdb"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.12-intel.egg/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.12-intel.egg/_mysql.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.12-intel.egg/_mysql.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.12-intel.egg/_mysql.so
尝试如下解决方案,均未果:
_mysql.so 相关信息:
MySQL_python-1.2.5-py2.7.egg-info lazybone$ file /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.12-intel.egg/_mysql.so
/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.12-intel.egg/_mysql.so: Mach-O universal binary with 2 architectures: [x86_64: Mach-O 64-bit bundle x86_64] [i386: Mach-O bundle i386]
/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.12-intel.egg/_mysql.so (for architecture x86_64): Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.12-intel.egg/_mysql.so (for architecture i386): Mach-O bundle i386
ps:同样机器配置,同事可以安装并使用!!!( Mysql 5.7.18 Homebrew + MySQL_python-1.2.4b4 )
1
fffflyfish 2017-07-03 11:52:15 +08:00
`pip install MySQL-python`
我记得要装一个 python-mysql 的 |
2
fffflyfish 2017-07-03 11:54:15 +08:00
@fffflyfish sorry 不对,请忽视
|
3
wellsc 2017-07-03 11:57:44 +08:00 via Android
不要用系统自带的 pye
|
4
wellsc 2017-07-03 11:58:01 +08:00 via Android
不要用系统自带的 python
|
5
AnyISalIn 2017-07-03 11:58:20 +08:00 via iPhone
装了 mysql-devel 么
|
6
J0k3r 2017-07-03 12:52:18 +08:00
pip install pymysql
|
7
g8287694 2017-07-03 12:54:59 +08:00
我记得 python 的 mysql 扩展好像一直在变的
|
8
EvansLyb 2017-07-03 12:57:33 +08:00
开发环境的话用 sqlite 代替吧
|
9
ansheng 2017-07-03 13:12:50 +08:00
pip install pymysql
|
10
scriptB0y 2017-07-03 13:32:29 +08:00
mysql 这个驱动挺难装的,我当时遇到很多麻烦,而且第一次花了很长时间之后把系统的 python 搞坏了,只好重装系统( osx )
一定要在虚拟环境用这个东西…… 而且安装的时候,貌似 mysql 服务是要开着的 另外我怀疑你这个 mysql 版本和 python-mysql 版本不对应,要注意 64 位还是 32 位,python-myql 版本支持不支持当前 python 版本和 mysql 版本 |
11
wanxi3 2017-07-03 15:36:03 +08:00
建议使用 pymysql 代替
|
12
robinshi2010 2017-07-03 16:03:03 +08:00
pip install PyMySQL
|
13
1iuh 2017-07-03 16:09:13 +08:00
|
14
1iuh 2017-07-03 16:13:53 +08:00
@1iuh #13 刚刚去看了一下,这个库主要是提供连接池的解决方案,应该还是需要用到 pymysql 来作为底层链接,所以我这个回复对楼主来说应该没有帮助。
|
15
springz 2017-07-03 16:16:52 +08:00
你打印下 Python 的可执行文件路径,你是不是用错了
|
16
debuggerx 2017-07-03 16:46:49 +08:00
MySQLConnector 就挺好用的啊,写的脚本几乎不用改 2.7 和 3.5 都能正常跑
|
18
zhujinhe 2017-07-03 16:47:07 +08:00
• You installed python
• You did brew install mysql • You did export PATH=$PATH:/usr/local/mysql/bin And finally, you did pip install MySQL-Python via: https://stackoverflow.com/questions/25459386/mac-os-x-environmenterror-mysql-config-not-found/25491082#25491082 |
19
halfcoder 2017-07-03 17:01:43 +08:00
是时候换用 mysqlclient 了 https://pypi.python.org/pypi/mysqlclient
|
21
kwdfmzhu OP @scriptB0y 版本都是对的,我下午的时候换了一台电脑,同样的步骤安装后就没有问题,看来应该是环境的问题引起的,具体是哪个环境估计得好好找了。。。
|
22
zzd1000 2017-07-03 19:36:21 +08:00
sudo install_name_tool -change libmysqlclient.18.dylib \
/usr/local/mysql/lib/libmysqlclient.18.dylib \ /Library/Python/2.7/site-packages/_mysql.so |
23
mingyun 2017-07-03 22:50:24 +08:00
pymysql +1
|
24
reyno 2017-07-03 23:26:31 +08:00 via iPhone
pip install pymysql
|
25
SlipStupig 2017-07-03 23:32:59 +08:00
需要 mysql 开发包才能编译过....不知道支不支持 mac,linux 下面一切正常
|
26
chengxiao 2017-07-04 07:39:51 +08:00 via iPhone
我昨天也是因为这个原因换了 pymysql ……
|