official doc
github.com/PyMySQL/mysqlclient-python
Linux
Note that this is a basic step. I can not support complete step for build for all environment. If you can see some error, you should fix it by yourself, or ask for support in some user forum. Don't file a issue on the issue tracker.
You may need to install the Python 3 and MySQL development headers and libraries like so:
-
$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential # Debian / Ubuntu
-
% sudo yum install python3-devel mysql-devel # Red Hat / CentOS
Then you can install mysqlclient via pip now:
$ pip install mysqlclient
ERROR: Command errored out with exit status 1
pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-2.0.1.tar.gz (87 kB)
Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed.
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-j73o9y1e/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-j73o9y1e/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-nes16jnc/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python3.5m/mysqlclient
cwd: /tmp/pip-install-j73o9y1e/mysqlclient/
Complete output (31 lines):
/usr/lib64/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
sudo yum -y install mariadb-devel gcc python35u-devel
/usr/bin/ld: cannot find -lmariadb
python3 setup.py build
running build
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-3.5/MySQLdb
running build_ext
building '_mysql' extension
gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -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,12,'final',0) -D__version__=1.3.12 -I/usr/include/mysql -I/usr/include/mysql/mysql -I/usr/include/python3.5m -c _mysql.c -o build/temp.linux-x86_64-3.5/_mysql.o
gcc -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-3.5/_mysql.o -L/usr/lib64/ -L/usr/lib64 -lmariadb -lpython3.5m -o build/lib.linux-x86_64-3.5/_mysql.cpython-35m-x86_64-linux-gnu.so
/usr/bin/ld: cannot find -lmariadb
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
yum install MariaDB-shared
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
sudo -H pip uninstall mysqlclient
Found existing installation: mysqlclient 2.0.1
Uninstalling mysqlclient-2.0.1:
Would remove:
/usr/lib64/python3.5/site-packages/MySQLdb/*
/usr/lib64/python3.5/site-packages/mysqlclient-2.0.1-py3.5.egg-info
Proceed (y/n)? y
Successfully uninstalled mysqlclient-2.0.1
sudo -H pip install --no-binary mysqlclient mysqlclient
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.5/site-packages/mysqlclient-1.3.12-py3.5-linux-x86_64.egg/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: libmariadb.so.18: cannot open shared object file: No such file or directory
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export PYTHONPATH=${PYTHONPATH}:/프로젝트설치경로
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.5/site-packages/mysqlclient-1.3.12-py3.5-linux-x86_64.egg/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: libmariadb.so.3: cannot open shared object file: No such file or directory
이 방법으로 하면 SQLALCHEMY가 일부만 동작한다 ㅡㅡ;;
import pymysql
pymysql.install_as_MySQLdb()
import MySQLdb
아래 방법으로 파이썬 환경 잡고 라이브러리 설치를 해준 후에 site-package를 다른 서버로 가져가서 사용 가능
sudo yum -y install gcc gcc-c++
sudo yum -y install zlib zlib-devel
sudo yum -y install libffi-devel
https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz
tar xzf Python-3.5.0.tgz
cd Python-3.5.0.tgz
./configure --enable-optimizations
make
make install
pip install mysqlclient
pip install MySQL-db
'Python > Python__works' 카테고리의 다른 글
calendar 를 이용해서 년-월-일 목록 뽑아내기 (0) | 2020.11.19 |
---|---|
dictionary (0) | 2020.10.12 |
서버의 로그를 파이썬으로 읽어서 slack으로 전달하기 (0) | 2020.09.24 |
datetime 활용하기 (0) | 2020.09.24 |
실행 중인 메서드이름, 파일 이름 (0) | 2020.09.24 |