CentOS 6.5, Python 2.7에서 mysqlclient 설치하기

mysqlclientMySQLdb를 개선한 것으로, Python 3도 지원한다. 

윈도우 7, Python 2.7에서는 ‘pip install mysqlclinet’ 명령어로 쉽게 설치된다. 그러나 CentOS 6.5에서는 아래와 같은 순서로 설치를 해야 한다. 

 
[USER@PLUTO bin]$ Sudo yum install python-devel mysql-devel
(catnap) [USER@PLUTO bin]$ python pip install mysqlclient
 
cs


참고

https://github.com/PyMySQL/mysqlclient-python


주의할 점

CentOS에 python-devel, mysql-devel가 없을 때 설치하면 아래와 같은 에러가 발생한다.

 
(catnap) [USER@PLUTO bin]$ python pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-1.3.7.tar.gz
Building wheels for collected packages: mysqlclient
  Running setup.py bdist_wheel for mysqlclient ... error
  Complete output from command /opt/Python27/catnap/bin/python --"import setuptools, tokenize;__file__='/tmp/pip-build-40FgWg/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -/tmp/tmpXTAm3Ipip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-2.7
  copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
  creating build/lib.linux-x86_64-2.7/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
  copying MySQLdb/compat.py -> build/lib.linux-x86_64-2.7/MySQLdb
  copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
  copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
  copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
  copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
  creating build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  running build_ext
  building '_mysql' extension
  creating build/temp.linux-x86_64-2.7
  gcc -pthread -fno-strict-aliasing --O2 -DNDEBUG --fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,3,7,'final',1-D__version__=1.3.7 -I/usr/include/mysql -I/usr/local/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o --pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -DUNIV_LINUX -DUNIV_LINUX
  _mysql.c:29:23: error: my_config.h: 그런 파일이나 디렉터리가 없습니다
  _mysql.c:30:19: error: mysql.h: 그런 파일이나 디렉터리가 없습니다
  _mysql.c:31:26: error: mysqld_error.h: 그런 파일이나 디렉터리가 없습니다
  _mysql.c:51:20: error: errmsg.h: 그런 파일이나 디렉터리가 없습니다
  _mysql.c:74: error: expected specifier-qualifier-list before ‘MYSQL’
  _mysql.c:88: error: expected specifier-qualifier-list before ‘MYSQL_RES’
  _mysql.c: In function ‘_mysql_Exception’:
  _mysql.c:129: warning: implicit declaration of function ‘mysql_errno’
 
 
 
(생략)
 
 
    _mysql.c:2297: error: ‘_mysql_ResultObject’ has no member named ‘result’
    _mysql.c:2298: error: ‘_mysql_ResultObject’ has no member named ‘result’
    _mysql.c: In function ‘_mysql_ResultObject_dealloc’:
    _mysql.c:2306: warning: implicit declaration of function ‘mysql_free_result’
    _mysql.c:2306: error: ‘_mysql_ResultObject’ has no member named ‘result’
    _mysql.c: At top level:
    _mysql.c:2563: error: ‘_mysql_ConnectionObject’ has no member named ‘open’
    _mysql.c:2570: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’
    _mysql.c:2577: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’
    _mysql.c:2584: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’
    _mysql.c:2592: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’
    _mysql.c:2654: error: ‘_mysql_ResultObject’ has no member named ‘converter’
    _mysql.c:2654: error: initializer element is not constant
    _mysql.c:2654: error: (near initialization for ‘_mysql_ResultObject_memberlist[0].offset’)
    _mysql.c:2661: error: ‘_mysql_ResultObject’ has no member named ‘has_next’
    _mysql.c:2661: error: initializer element is not constant
    _mysql.c:2661: error: (near initialization for ‘_mysql_ResultObject_memberlist[1].offset’)
    _mysql.c: In function ‘_mysql_ConnectionObject_getattro’:
    _mysql.c:2680: error: ‘_mysql_ConnectionObject’ has no member named ‘open’
    error: command 'gcc' failed with exit status 1
 
    ----------------------------------------
Command "/opt/Python27/catnap/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-40FgWg/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n''\n'), __file__, 'exec'))" install --record /tmp/pip-T_qtXx-record/install-record.txt --single-version-externally-managed --compile --install-headers /opt/Python27/catnap/include/site/python2.7/mysqlclient" failed with error code 1 in /tmp/pip-build-40FgWg/mysqlclient/
(catnap) [USER@PLUTO bin]$
 
cs



댓글 쓰기

0 댓글