V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
alfer
V2EX  ›  Python

centos7 安装 python 的 mysql 驱动 mysqlclient,报错,请问如何解决?

  •  
  •   alfer · 2016-05-22 19:09:29 +08:00 · 5551 次点击
    这是一个创建于 3096 天前的主题,其中的信息可能已经有所发展或是发生改变。
    [root@centos02 mysqlclient-1.3.7]# python setup.py build
    running build
    running build_py
    copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
    running build_ext
    building '_mysql' extension
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,3,7,'final',1) -D__version__=1.3.7 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -fstack-protector -m64 -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing
    In file included from /usr/include/python2.7/pyconfig.h:6:0,
    from /usr/include/python2.7/Python.h:8,
    from _mysql.c:40:
    /usr/include/python2.7/pyconfig-64.h:1182:0: warning: "_POSIX_C_SOURCE" redefined [enabled by default]
    #define _POSIX_C_SOURCE 200112L
    ^
    In file included from /usr/include/sys/types.h:25:0,
    from /usr/include/mysql/mysql.h:47,
    from _mysql.c:30:
    /usr/include/features.h:168:0: note: this is the location of the previous definition
    # define _POSIX_C_SOURCE 200809L
    ^
    In file included from /usr/include/python2.7/pyconfig.h:6:0,
    from /usr/include/python2.7/Python.h:8,
    from _mysql.c:40:
    /usr/include/python2.7/pyconfig-64.h:1204:0: warning: "_XOPEN_SOURCE" redefined [enabled by default]
    #define _XOPEN_SOURCE 600
    ^
    In file included from /usr/include/sys/types.h:25:0,
    from /usr/include/mysql/mysql.h:47,
    from _mysql.c:30:
    /usr/include/features.h:170:0: note: this is the location of the previous definition
    # define _XOPEN_SOURCE 700
    ^
    gcc -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64 -L/usr/lib64 -lmysqlclient -lpthread -lm -lrt -ldl -lpython2.7 -o build/lib.linux-x86_64-2.7/_mysql.so
    /usr/bin/ld: cannot find -lmysqlclient
    collect2: error: ld returned 1 exit status
    error: command 'gcc' failed with exit status 1
    7 条回复    2016-10-19 09:33:19 +08:00
    janxin
        1
    janxin  
       2016-05-22 20:45:46 +08:00
    /usr/bin/ld: cannot find -lmysqlclient

    mysql-client 装了吗?
    alfer
        2
    alfer  
    OP
       2016-05-22 21:28:24 +08:00
    @janxin 装了,问题已经解决了。
    alfer
        3
    alfer  
    OP
       2016-05-22 21:33:27 +08:00
    这个问题发现是 CentOS Linux release 7.2.1511 系统中装的 mariadb-libs 和自己装的 MySQL-server-5.6.30 的冲突了,所以卸载 mariadb 后导致组建缺失(libmysqlclient.so.18),致使安装 mysqlclient 报错。
    解决办法:先安装 mysqlclient ,再安装 mysql5.6
    但是还有遗留问题:因为安装 mysql 和 centos7 自带的 mariadb 有冲突,导致两者不能共存,卸载 mariadb 后,安装好的 mysqlclient 依然不能正常使用,报错如下:
    >>> import MySQLdb
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "build/bdist.linux-x86_64/egg/MySQLdb/__init__.py", line 19, in <module>
    File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in <module>
    File "build/bdist.linux-x86_64/egg/_mysql.py", line 6, in __bootstrap__
    ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
    patrickstar
        4
    patrickstar  
       2016-05-22 21:53:13 +08:00
    针对不同开发环境分别建立 python 虚拟环境(比如用 pyvenv ),不要安装到系统环境中去
    msg7086
        5
    msg7086  
       2016-05-23 01:41:30 +08:00
    所以为什么要装 MySQL 呢……(
    要装也建议打包成软件包然后再替换系统组件来着。
    ToughGuy
        6
    ToughGuy  
       2016-05-23 10:26:22 +08:00
    yum -y install mariadb-devel python-devel
    alfer
        7
    alfer  
    OP
       2016-10-19 09:33:19 +08:00
    建议用 mariadb+mysqlclient ,安装方便,可以避免卸载 mariadb 后 mysql+mysqlclient 的少包问题
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5470 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 07:01 · PVG 15:01 · LAX 23:01 · JFK 02:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.