Python Snippet - mysqlclient 패키지 설치 시 에러 해결

해결을 위해 여러 패키지를 설치한 것을 정리합니다.

1. mysqlclient 패키지 설치 시 발생한 에러

# pip install mysqlclient
Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    Complete output from command /root/.pyenv/versions/3.6.3/envs/suwoni-codelab-backend/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-7z9n6tvj/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-81tkwz4c/install-record.txt --single-version-externally-managed --compile --install-headers /root/.pyenv/versions/3.6.3/envs/suwoni-codelab-backend/include/site/python3.6/mysqlclient:
    /root/.pyenv/versions/3.6.3/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    copying _mysql_exceptions.py -> build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-x86_64-3.6/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-x86_64-3.6/MySQLdb
    creating build/lib.linux-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.linux-x86_64-3.6
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,3,13,'final',0) -D__version__=1.3.13 -I/usr/include/mysql -I/usr/include/mysql/mysql -I/root/.pyenv/versions/3.6.3/envs/suwoni-codelab-backend/include -I/root/.pyenv/versions/3.6.3/include/python3.6m -c _mysql.c -o build/temp.linux-x86_64-3.6/_mysql.o
    In file included from _mysql.c:29:0:
    /usr/include/mysql/mysql.h:440:3: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
       MYSQL_CLIENT_PLUGIN_HEADER
       ^
    gcc -pthread -shared -L/root/.pyenv/versions/3.6.3/lib -L/root/.pyenv/versions/3.6.3/lib build/temp.linux-x86_64-3.6/_mysql.o -L/usr/lib64/ -lmariadb -lz -ldl -lm -lpthread -lssl -lcrypto -o build/lib.linux-x86_64-3.6/_mysql.cpython-36m-x86_64-linux-gnu.so
    /bin/ld: cannot find -lmariadb
    collect2: error: ld returned 1 exit status
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/root/.pyenv/versions/3.6.3/envs/suwoni-codelab-backend/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-7z9n6tvj/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-81tkwz4c/install-record.txt --single-version-externally-managed --compile --install-headers /root/.pyenv/versions/3.6.3/envs/suwoni-codelab-backend/include/site/python3.6/mysqlclient" failed with error code 1 in /tmp/pip-install-7z9n6tvj/mysqlclient/

2. 해결을 위해 설치한 패키지

  • 설치되어 있던 패키지도 삭제 후 재설치 시도
$ yum -y install gcc gcc-c++ kernel-devel
$ yum -y install python-devel libxslt-devel libffi-devel openssl-devel
  • EPEL 패키지 repository
  • https://fedoraproject.org/wiki/EPEL
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  • python34-devel 패키지 설치
yum install python34-devel