Mac OS X 10.8.3安装MySQLdb模块失败,求解脱。 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yibin001
V2EX    macOS

Mac OS X 10.8.3安装MySQLdb模块失败,求解脱。

  •  
  •   yibin001 2013-05-19 17:29:59 +08:00 4312 次点击
    这是一个创建于 4535 天前的主题,其中的信息可能已经有所发展或是发生改变。
    10.8.3中的Python有3个版本:2.5、2.6、2.7,默认是2.7,已通过defaults改为2.6了

    yibintek iMac Book-Pro:~ yibin$ python
    Python 2.6.7 (r267:88850, Oct 11 2012, 20:15:00)
    [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.

    MySQL_python的版本:MySQL-python-1.2.4b4
    执行sudo python setup.py install,输出:

    yibintek iMac Book-Pro:MySQL-python-1.2.4b4 yibin$ sudo python setup.py install
    Password:
    running install
    running bdist_egg
    running egg_info
    writing MySQL_python.egg-info/PKG-INFO
    writing top-level names to MySQL_python.egg-info/top_level.txt
    writing dependency_links to MySQL_python.egg-info/dependency_links.txt
    writing MySQL_python.egg-info/PKG-INFO
    writing top-level names to MySQL_python.egg-info/top_level.txt
    writing dependency_links to MySQL_python.egg-info/dependency_links.txt
    reading manifest file 'MySQL_python.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'MySQL_python.egg-info/SOURCES.txt'
    installing library code to build/bdist.macosx-10.8-intel/egg
    running install_lib
    running build_py
    copying MySQLdb/release.py -> build/lib.macosx-10.8-intel-2.7/MySQLdb
    running build_ext
    creating build/bdist.macosx-10.8-intel/egg
    copying build/lib.macosx-10.8-intel-2.7/_mysql.so -> build/bdist.macosx-10.8-intel/egg
    copying build/lib.macosx-10.8-intel-2.7/_mysql_exceptions.py -> build/bdist.macosx-10.8-intel/egg
    creating build/bdist.macosx-10.8-intel/egg/MySQLdb
    copying build/lib.macosx-10.8-intel-2.7/MySQLdb/__init__.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb
    copying build/lib.macosx-10.8-intel-2.7/MySQLdb/connections.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb
    creating build/bdist.macosx-10.8-intel/egg/MySQLdb/constants
    copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/__init__.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants
    copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/CLIENT.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants
    copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/CR.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants
    copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/ER.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants
    copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants
    copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/FLAG.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants
    copying build/lib.macosx-10.8-intel-2.7/MySQLdb/constants/REFRESH.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb/constants
    copying build/lib.macosx-10.8-intel-2.7/MySQLdb/converters.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb
    copying build/lib.macosx-10.8-intel-2.7/MySQLdb/cursors.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb
    copying build/lib.macosx-10.8-intel-2.7/MySQLdb/release.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb
    copying build/lib.macosx-10.8-intel-2.7/MySQLdb/times.py -> build/bdist.macosx-10.8-intel/egg/MySQLdb
    byte-compiling build/bdist.macosx-10.8-intel/egg/_mysql_exceptions.py to _mysql_exceptions.pyc
    byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/__init__.py to __init__.pyc
    byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/connections.py to connections.pyc
    byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/__init__.py to __init__.pyc
    byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc
    byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/CR.py to CR.pyc
    byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/ER.py to ER.pyc
    byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc
    byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/FLAG.py to FLAG.pyc
    byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc
    byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/converters.py to converters.pyc
    byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/cursors.py to cursors.pyc
    byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/release.py to release.pyc
    byte-compiling build/bdist.macosx-10.8-intel/egg/MySQLdb/times.py to times.pyc
    creating stub loader for _mysql.so
    byte-compiling build/bdist.macosx-10.8-intel/egg/_mysql.py to _mysql.pyc
    creating build/bdist.macosx-10.8-intel/egg/EGG-INFO
    copying MySQL_python.egg-info/PKG-INFO -> build/bdist.macosx-10.8-intel/egg/EGG-INFO
    copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.macosx-10.8-intel/egg/EGG-INFO
    copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.macosx-10.8-intel/egg/EGG-INFO
    copying MySQL_python.egg-info/top_level.txt -> build/bdist.macosx-10.8-intel/egg/EGG-INFO
    writing build/bdist.macosx-10.8-intel/egg/EGG-INFO/native_libs.txt
    zip_safe flag not set; analyzing archive contents...
    creating 'dist/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg' and adding 'build/bdist.macosx-10.8-intel/egg' to it
    removing 'build/bdist.macosx-10.8-intel/egg' (and everything under it)
    Processing MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg
    removing '/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg' (and everything under it)
    creating /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg
    Extracting MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg to /Library/Python/2.7/site-packages
    MySQL-python 1.2.4b4 is already the active version in easy-install.pth

    Installed /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg
    Processing dependencies for MySQL-python==1.2.4b4
    Finished processing dependencies for MySQL-python==1.2.4b4



    测试:
    >>> import MySQLdb
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "MySQLdb/__init__.py", line 19, in <module>
    import _mysql
    ImportError: No module named _mysql

    为什么出现找不到_mysql这个模块?
    6 条回复    2019-04-15 18:00:11 +08:00
    wtracyliu
        1
    wtracyliu  
       2013-05-19 18:17:06 +08:00
    看上去装到python2.7的Library下面了哦...我猜你sudo 下面的默认python 是2.7 估计也得改成2.6才行 btw,为什么不用virtualenv 或者virtualenvwrapper之类的东西呢
    yibin001
        2
    yibin001  
    OP
       2013-05-19 18:28:02 +08:00
    @wtracyliu
    为什么不用virtualenv 或者virtualenvwrapper之类的东西呢

    没有了解过。。我需要扫一下盲了。。。
    wtracyliu
        3
    wtracyliu  
       2013-05-19 18:31:09 +08:00
    感觉virtualenv之类的确实不错... 最开始不知道,把系统自带的python下面的lib装的乱七八糟...自从用了这货,省心多了.. 楼主试试呗` virtualenv可以指定python版本 这样也不用去改系统自己的python,而且就算装错了打不了重新弄一个env
    yibin001
        4
    yibin001  
    OP
       2013-05-19 18:39:26 +08:00
    @wtracyliu
    Thank u,我这就试试。
    julyclyde
        5
    julyclyde  
       2013-05-20 10:06:03 +08:00
    \mysqldb编译需要libmysqlclient 很奇怪你咋编译成功的
    建议用pymysql代替之,纯python代码

    说正题,你这个问题应该是没权限安装到系统目录里,所以其实安装过程是失败了的
    运行python setup.py install的时候用sudo试试
    或者建议virtualenv里折腾
    peilunz
        6
    peilunz  
       2019-04-15 18:00:11 +08:00
    需要下个东西,然后改下源码。。具体看下 http://www.zzhub.cn/article-detials/1
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2599 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 09:52 PVG 17:52 LAX 02:52 JFK 05:52
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86