관리 메뉴

개발이야기

[ Python Skill ] Python 3.x 에서 MySQLdb 설치하기 본문

Python /Python Skill

[ Python Skill ] Python 3.x 에서 MySQLdb 설치하기

안성주지몬 2019. 6. 19. 00:00

이번 포스팅에서는 python3.x 에서 MySQLdb 라이브러리를 설치했던 저의 전 과정을 알려드리겠습니다.

 

- 시도 

python 2.x 는 mysql-python 설치

python 3.x 는 mysqlclient 설치

 

pip3 install mysqlclient

 

- 에러 발생

" OSError: mysql_config not found "

 

- 에러 해결 방안 1

1) 

sudo apt-get update

 

2) 

sudo apt-get install python3-dev libmysqlclient-dev

 

3)

sudo pip3 install mysqlclient

 

- 에러 발생

" error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 "

 

- 에러 해결 방안 2

sudo apt-get install python3 python-dev python3-dev \
     build-essential libssl-dev libffi-dev \
     libxml2-dev libxslt1-dev zlib1g-dev \
     python-pip

 

이후

 

sudo pip3 install mysqlclient 를 다시 시도하면 MySQLdb 가 성공적으로 설치 되었습니다.

 

 

+) 

에러 해결 방안 2를 한 이후에도 

 

" error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 "

 

같은 에러가 발생한다면 자신의 버전에 맞게 아래의 명령문을 실행한 후 다시 설치해보시길 바랍니다.

 

" sudo apt-get install python3.7-dev " (버전이 3.7인 경우) 

 

참고

[1]시도: https://stackoverflow.com/questions/454854/no-module-named-mysqldb

 

No module named MySQLdb

I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. I am using it in Windows Vista.

stackoverflow.com

[2] 에러 해결방안1: https://raspberrypi.stackexchange.com/questions/78215/how-to-connect-mysqldb-in-python-3 

 

How to connect MySQLdb in Python 3?

I want to connect MySQLdb with Raspberry Pi. But when running my program, I get this error: $ sudo python3 readMQ2sql.py Traceback (most recent call last): File "readMQ2sql.py", line 17, in <...

raspberrypi.stackexchange.com

[3] 에러 해결방안 2 : https://github.com/scrapy/scrapy/issues/2115

 

' error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 ' · Issue #2115 · scrapy/scrapy

I wanted to install scrapy in virtualenv using pip (Python 3.5) but I get the following error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 I tried with Python 2.7 but I get the...

github.com

[4] +

https://stackoverflow.com/questions/26053982/setup-script-exited-with-error-command-x86-64-linux-gnu-gcc-failed-with-exit

 

setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

When I try to install odoo-server, I got the following error: error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 Could anyone help me to solve this i...

stackoverflow.com

 

Comments