글이 너무 길어져서 만드는 목차
결론: Django에서 Mysql 모듈을 사용하려면 아래 과정을 먼저 거쳐야 한다~
pip install --upgrade pip setuptools wheel
sudo apt install libmysqlclient-dev gcc python3-dev
pip install mysqlclient
0. 오류의 시작
Django에서 기본 설정인 SQLite3을 사용하지 않고 MariaDB를 사용하고자 할 때 생각 못한 오류가 발생했다.
$ python3 manage.py migrate
Traceback (most recent call last):
File "{venv 경로}/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "{venv 경로}/lib/python3.8/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "{venv 경로}/lib/python3.8/site-packages/django/core/management/__init__.py", line 416, in execute
django.setup()
File "{venv 경로}/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "{venv 경로}/lib/python3.8/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "{venv 경로}/lib/python3.8/site-packages/django/apps/config.py", line 269, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "{venv 경로}/lib/python3.8/site-packages/django/contrib/auth/models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "{venv 경로}/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 57, in <module>
class AbstractBaseUser(models.Model):
File "{venv 경로}/lib/python3.8/site-packages/django/db/models/base.py", line 143, in __new__
new_class.add_to_class("_meta", Options(meta, app_label))
File "{venv 경로}/lib/python3.8/site-packages/django/db/models/base.py", line 371, in add_to_class
value.contribute_to_class(cls, name)
File "{venv 경로}/lib/python3.8/site-packages/django/db/models/options.py", line 243, in contribute_to_class
self.db_table, connection.ops.max_name_length()
File "{venv 경로}/lib/python3.8/site-packages/django/utils/connection.py", line 15, in __getattr__
return getattr(self._connections[self._alias], item)
File "{venv 경로}/lib/python3.8/site-packages/django/utils/connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
File "{venv 경로}/lib/python3.8/site-packages/django/db/utils.py", line 193, in create_connection
backend = load_backend(db["ENGINE"])
File "{venv 경로}/lib/python3.8/site-packages/django/db/utils.py", line 113, in load_backend
return import_module("%s.base" % backend_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "{venv 경로}/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 17, in <module>
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
'아, Django에서 Mysql 라인의 DB를 사용하려면 mysqlclient가 필요하구나?'
하고 설치하다가 오류를 몇 번이나 더 봤다.
아래는 오류별 솔루션 나열이다.
1. pip 버전을 확인해 주세요~
$ pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-2.1.1.tar.gz (88 kB)
ERROR: Command errored out with exit status 1:
command: {venv 경로}/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-doulwy0r/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-doulwy0r/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-doulwy0r/mysqlclient/pip-egg-info
cwd: /tmp/pip-install-doulwy0r/mysqlclient/
Complete output (15 lines):
/bin/sh: 1: mysql_config: not found
/bin/sh: 1: mariadb_config: not found
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-doulwy0r/mysqlclient/setup.py", line 15, in <module>
metadata, options = get_config()
File "/tmp/pip-install-doulwy0r/mysqlclient/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-doulwy0r/mysqlclient/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
mysql_config --version
mariadb_config --version
mysql_config --libs
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
$ pip install --upgrade pip
Collecting pip
Downloading pip-23.1.2-py3-none-any.whl (2.1 MB)
|████████████████████████████████| 2.1 MB 11.6 MB/s
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.0.2
Uninstalling pip-20.0.2:
Successfully uninstalled pip-20.0.2
Successfully installed pip-23.1.2
2. wheel이 에러 났어요~
$ pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-2.1.1.tar.gz (88 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [27 lines of output]
/bin/sh: 1: mysql_config: not found
/bin/sh: 1: mariadb_config: not found
/bin/sh: 1: mysql_config: not found
mysql_config --version
mariadb_config --version
mysql_config --libs
Traceback (most recent call last):
File "{venv 경로}/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
File "{venv 경로}/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "{venv 경로}/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
File "/tmp/pip-build-env-qdutxhdv/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
File "/tmp/pip-build-env-qdutxhdv/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
self.run_setup()
File "/tmp/pip-build-env-qdutxhdv/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 487, in run_setup
super(_BuildMetaLegacyBackend,
File "/tmp/pip-build-env-qdutxhdv/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 338, in run_setup
exec(code, locals())
File "<string>", line 15, in <module>
File "/tmp/pip-install-3a9oru3j/mysqlclient_2e8f0ff252924ac597d47ca10d023d7f/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-3a9oru3j/mysqlclient_2e8f0ff252924ac597d47ca10d023d7f/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
$ pip install --upgrade setuptools wheel
Requirement already satisfied: setuptools in {venv 경로}/lib/python3.8/site-packages (67.7.2)
Collecting wheel
Using cached wheel-0.40.0-py3-none-any.whl (64 kB)
Installing collected packages: wheel
Successfully installed wheel-0.40.0
3. 메타데이터가 없어요~
(뭐가 없는데 ㅂㄷㅂㄷ)
$ pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-2.1.1.tar.gz (88 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [16 lines of output]
/bin/sh: 1: mysql_config: not found
/bin/sh: 1: mariadb_config: not found
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-sea53081/mysqlclient_a8a8b56096ac41b385727d9e72c91bc8/setup.py", line 15, in <module>
metadata, options = get_config()
File "/tmp/pip-install-sea53081/mysqlclient_a8a8b56096ac41b385727d9e72c91bc8/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-sea53081/mysqlclient_a8a8b56096ac41b385727d9e72c91bc8/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
mysql_config --version
mariadb_config --version
mysql_config --libs
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
$ sudo apt install libmysqlclient-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libc-dev-bin libc6-dev libcrypt-dev libssl-dev linux-libc-dev manpages-dev zlib1g-dev
Suggested packages:
glibc-doc libssl-doc
The following NEW packages will be installed:
libc-dev-bin libc6-dev libcrypt-dev libmysqlclient-dev libssl-dev linux-libc-dev manpages-dev zlib1g-dev
0 upgraded, 8 newly installed, 0 to remove and 9 not upgraded.
Need to get 9,488 kB of archives.
After this operation, 49.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libc-dev-bin amd64 2.31-0ubuntu9.9 [71.8 kB]
Get:2 http://mirror.kakao.com/ubuntu focal-updates/main amd64 linux-libc-dev amd64 5.4.0-148.165 [1,120 kB]
Get:3 http://mirror.kakao.com/ubuntu focal/main amd64 libcrypt-dev amd64 1:4.4.10-10ubuntu4 [104 kB]
Get:4 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libc6-dev amd64 2.31-0ubuntu9.9 [2,519 kB]
Get:5 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libssl-dev amd64 1.1.1f-1ubuntu2.18 [1,586 kB]
Get:6 http://mirror.kakao.com/ubuntu focal-updates/main amd64 zlib1g-dev amd64 1:1.2.11.dfsg-2ubuntu1.5 [155 kB]
Get:7 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libmysqlclient-dev amd64 8.0.33-0ubuntu0.20.04.1 [1,667 kB]
Get:8 http://mirror.kakao.com/ubuntu focal/main amd64 manpages-dev all 5.05-1 [2,266 kB]
Fetched 9,488 kB in 0s (30.8 MB/s)
Selecting previously unselected package libc-dev-bin.
(Reading database ... 115915 files and directories currently installed.)
Preparing to unpack .../0-libc-dev-bin_2.31-0ubuntu9.9_amd64.deb ...
Unpacking libc-dev-bin (2.31-0ubuntu9.9) ...
Selecting previously unselected package linux-libc-dev:amd64.
Preparing to unpack .../1-linux-libc-dev_5.4.0-148.165_amd64.deb ...
Unpacking linux-libc-dev:amd64 (5.4.0-148.165) ...
Selecting previously unselected package libcrypt-dev:amd64.
Preparing to unpack .../2-libcrypt-dev_1%3a4.4.10-10ubuntu4_amd64.deb ...
Unpacking libcrypt-dev:amd64 (1:4.4.10-10ubuntu4) ...
Selecting previously unselected package libc6-dev:amd64.
Preparing to unpack .../3-libc6-dev_2.31-0ubuntu9.9_amd64.deb ...
Unpacking libc6-dev:amd64 (2.31-0ubuntu9.9) ...
Selecting previously unselected package libssl-dev:amd64.
Preparing to unpack .../4-libssl-dev_1.1.1f-1ubuntu2.18_amd64.deb ...
Unpacking libssl-dev:amd64 (1.1.1f-1ubuntu2.18) ...
Selecting previously unselected package zlib1g-dev:amd64.
Preparing to unpack .../5-zlib1g-dev_1%3a1.2.11.dfsg-2ubuntu1.5_amd64.deb ...
Unpacking zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu1.5) ...
Selecting previously unselected package libmysqlclient-dev.
Preparing to unpack .../6-libmysqlclient-dev_8.0.33-0ubuntu0.20.04.1_amd64.deb ...
Unpacking libmysqlclient-dev (8.0.33-0ubuntu0.20.04.1) ...
Selecting previously unselected package manpages-dev.
Preparing to unpack .../7-manpages-dev_5.05-1_all.deb ...
Unpacking manpages-dev (5.05-1) ...
Setting up manpages-dev (5.05-1) ...
Setting up linux-libc-dev:amd64 (5.4.0-148.165) ...
Setting up libssl-dev:amd64 (1.1.1f-1ubuntu2.18) ...
Setting up libcrypt-dev:amd64 (1:4.4.10-10ubuntu4) ...
Setting up libc-dev-bin (2.31-0ubuntu9.9) ...
Setting up libc6-dev:amd64 (2.31-0ubuntu9.9) ...
Setting up zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu1.5) ...
Setting up libmysqlclient-dev (8.0.33-0ubuntu0.20.04.1) ...
Processing triggers for man-db (2.9.1-1) ...
4. gcc도 없어요~ ㅎㅎㅎ
$ pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-2.1.1.tar.gz (88 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: mysqlclient
Building wheel for mysqlclient (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [40 lines of output]
mysql_config --version
['8.0.33']
mysql_config --libs
['-L/usr/lib/x86_64-linux-gnu', '-lmysqlclient', '-lpthread', '-ldl', '-lssl', '-lcrypto', '-lresolv', '-lm', '-lrt']
mysql_config --cflags
['-I/usr/include/mysql']
ext_options:
library_dirs: ['/usr/lib/x86_64-linux-gnu']
libraries: ['mysqlclient', 'pthread', 'dl', 'resolv', 'm', 'rt']
extra_compile_args: ['-std=c99']
extra_link_args: []
include_dirs: ['/usr/include/mysql']
extra_objects: []
define_macros: [('version_info', "(2,1,1,'final',0)"), ('__version__', '2.1.1')]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-38
creating build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
creating build/lib.linux-x86_64-cpython-38/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-cpython-38/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-38/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-cpython-38/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-cpython-38/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-38/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-cpython-38/MySQLdb/constants
running build_ext
building 'MySQLdb._mysql' extension
creating build/temp.linux-x86_64-cpython-38
creating build/temp.linux-x86_64-cpython-38/MySQLdb
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Dversion_info=(2,1,1,'final',0) -D__version__=2.1.1 -I/usr/include/mysql -I{venv 경로}/include -I/usr/include/python3.8 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-cpython-38/MySQLdb/_mysql.o -std=c99
error: command 'x86_64-linux-gnu-gcc' failed: No such file or directory
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for mysqlclient
Running setup.py clean for mysqlclient
Failed to build mysqlclient
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
$ sudo apt install gcc
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
gcc-9 libasan5 libatomic1 libcc1-0 libgcc-9-dev libitm1 liblsan0 libquadmath0 libtsan0 libubsan1
Suggested packages:
gcc-multilib make autoconf automake libtool flex bison gdb gcc-doc gcc-9-multilib gcc-9-doc gcc-9-locales
The following NEW packages will be installed:
gcc gcc-9 libasan5 libatomic1 libcc1-0 libgcc-9-dev libitm1 liblsan0 libquadmath0 libtsan0 libubsan1
0 upgraded, 11 newly installed, 0 to remove and 9 not upgraded.
Need to get 17.2 MB of archives.
After this operation, 76.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libcc1-0 amd64 10.3.0-1ubuntu1~20.04 [48.8 kB]
Get:2 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libitm1 amd64 10.3.0-1ubuntu1~20.04 [26.2 kB]
Get:3 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libatomic1 amd64 10.3.0-1ubuntu1~20.04 [9,284 B]
Get:4 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libasan5 amd64 9.4.0-1ubuntu1~20.04.1 [2,751 kB]
Get:5 http://mirror.kakao.com/ubuntu focal-updates/main amd64 liblsan0 amd64 10.3.0-1ubuntu1~20.04 [835 kB]
Get:6 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libtsan0 amd64 10.3.0-1ubuntu1~20.04 [2,009 kB]
Get:7 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libubsan1 amd64 10.3.0-1ubuntu1~20.04 [784 kB]
Get:8 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libquadmath0 amd64 10.3.0-1ubuntu1~20.04 [146 kB]
Get:9 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libgcc-9-dev amd64 9.4.0-1ubuntu1~20.04.1 [2,359 kB]
Get:10 http://mirror.kakao.com/ubuntu focal-updates/main amd64 gcc-9 amd64 9.4.0-1ubuntu1~20.04.1 [8,274 kB]
Get:11 http://mirror.kakao.com/ubuntu focal/main amd64 gcc amd64 4:9.3.0-1ubuntu2 [5,208 B]
Fetched 17.2 MB in 1s (29.6 MB/s)
Selecting previously unselected package libcc1-0:amd64.
(Reading database ... 119778 files and directories currently installed.)
Preparing to unpack .../00-libcc1-0_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libcc1-0:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libitm1:amd64.
Preparing to unpack .../01-libitm1_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libitm1:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libatomic1:amd64.
Preparing to unpack .../02-libatomic1_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libatomic1:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libasan5:amd64.
Preparing to unpack .../03-libasan5_9.4.0-1ubuntu1~20.04.1_amd64.deb ...
Unpacking libasan5:amd64 (9.4.0-1ubuntu1~20.04.1) ...
Selecting previously unselected package liblsan0:amd64.
Preparing to unpack .../04-liblsan0_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking liblsan0:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libtsan0:amd64.
Preparing to unpack .../05-libtsan0_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libtsan0:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libubsan1:amd64.
Preparing to unpack .../06-libubsan1_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libubsan1:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libquadmath0:amd64.
Preparing to unpack .../07-libquadmath0_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libquadmath0:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libgcc-9-dev:amd64.
Preparing to unpack .../08-libgcc-9-dev_9.4.0-1ubuntu1~20.04.1_amd64.deb ...
Unpacking libgcc-9-dev:amd64 (9.4.0-1ubuntu1~20.04.1) ...
Selecting previously unselected package gcc-9.
Preparing to unpack .../09-gcc-9_9.4.0-1ubuntu1~20.04.1_amd64.deb ...
Unpacking gcc-9 (9.4.0-1ubuntu1~20.04.1) ...
Selecting previously unselected package gcc.
Preparing to unpack .../10-gcc_4%3a9.3.0-1ubuntu2_amd64.deb ...
Unpacking gcc (4:9.3.0-1ubuntu2) ...
Setting up libasan5:amd64 (9.4.0-1ubuntu1~20.04.1) ...
Setting up libquadmath0:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up libatomic1:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up libubsan1:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up libcc1-0:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up liblsan0:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up libitm1:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up libtsan0:amd64 (10.3.0-1ubuntu1~20.04) ...
Setting up libgcc-9-dev:amd64 (9.4.0-1ubuntu1~20.04.1) ...
Setting up gcc-9 (9.4.0-1ubuntu1~20.04.1) ...
Setting up gcc (4:9.3.0-1ubuntu2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
5. 응 Python.h 없어~
(도대체 그게 뭔데;;;)
$ pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-2.1.1.tar.gz (88 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: mysqlclient
Building wheel for mysqlclient (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [44 lines of output]
mysql_config --version
['8.0.33']
mysql_config --libs
['-L/usr/lib/x86_64-linux-gnu', '-lmysqlclient', '-lpthread', '-ldl', '-lssl', '-lcrypto', '-lresolv', '-lm', '-lrt']
mysql_config --cflags
['-I/usr/include/mysql']
ext_options:
library_dirs: ['/usr/lib/x86_64-linux-gnu']
libraries: ['mysqlclient', 'pthread', 'dl', 'resolv', 'm', 'rt']
extra_compile_args: ['-std=c99']
extra_link_args: []
include_dirs: ['/usr/include/mysql']
extra_objects: []
define_macros: [('version_info', "(2,1,1,'final',0)"), ('__version__', '2.1.1')]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-38
creating build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-cpython-38/MySQLdb
creating build/lib.linux-x86_64-cpython-38/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-cpython-38/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-38/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-cpython-38/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-cpython-38/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-38/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-cpython-38/MySQLdb/constants
running build_ext
building 'MySQLdb._mysql' extension
creating build/temp.linux-x86_64-cpython-38
creating build/temp.linux-x86_64-cpython-38/MySQLdb
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Dversion_info=(2,1,1,'final',0) -D__version__=2.1.1 -I/usr/include/mysql -I{venv 경로}/include -I/usr/include/python3.8 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-cpython-38/MySQLdb/_mysql.o -std=c99
MySQLdb/_mysql.c:46:10: fatal error: Python.h: No such file or directory
46 | #include "Python.h"
| ^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for mysqlclient
Running setup.py clean for mysqlclient
Failed to build mysqlclient
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
$ sudo apt install python3-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libexpat1-dev libpython3-dev libpython3.8-dev python3.8-dev
The following NEW packages will be installed:
libexpat1-dev libpython3-dev libpython3.8-dev python3-dev python3.8-dev
0 upgraded, 5 newly installed, 0 to remove and 9 not upgraded.
Need to get 4,591 kB of archives.
After this operation, 21.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libexpat1-dev amd64 2.2.9-1ubuntu0.6 [116 kB]
Get:2 http://mirror.kakao.com/ubuntu focal-updates/main amd64 libpython3.8-dev amd64 3.8.10-0ubuntu1~20.04.7 [3,953 kB]
Get:3 http://mirror.kakao.com/ubuntu focal/main amd64 libpython3-dev amd64 3.8.2-0ubuntu2 [7,236 B]
Get:4 http://mirror.kakao.com/ubuntu focal-updates/main amd64 python3.8-dev amd64 3.8.10-0ubuntu1~20.04.7 [514 kB]
Get:5 http://mirror.kakao.com/ubuntu focal/main amd64 python3-dev amd64 3.8.2-0ubuntu2 [1,212 B]
Fetched 4,591 kB in 0s (12.3 MB/s)
Selecting previously unselected package libexpat1-dev:amd64.
(Reading database ... 120044 files and directories currently installed.)
Preparing to unpack .../libexpat1-dev_2.2.9-1ubuntu0.6_amd64.deb ...
Unpacking libexpat1-dev:amd64 (2.2.9-1ubuntu0.6) ...
Selecting previously unselected package libpython3.8-dev:amd64.
Preparing to unpack .../libpython3.8-dev_3.8.10-0ubuntu1~20.04.7_amd64.deb ...
Unpacking libpython3.8-dev:amd64 (3.8.10-0ubuntu1~20.04.7) ...
Selecting previously unselected package libpython3-dev:amd64.
Preparing to unpack .../libpython3-dev_3.8.2-0ubuntu2_amd64.deb ...
Unpacking libpython3-dev:amd64 (3.8.2-0ubuntu2) ...
Selecting previously unselected package python3.8-dev.
Preparing to unpack .../python3.8-dev_3.8.10-0ubuntu1~20.04.7_amd64.deb ...
Unpacking python3.8-dev (3.8.10-0ubuntu1~20.04.7) ...
Selecting previously unselected package python3-dev.
Preparing to unpack .../python3-dev_3.8.2-0ubuntu2_amd64.deb ...
Unpacking python3-dev (3.8.2-0ubuntu2) ...
Setting up libexpat1-dev:amd64 (2.2.9-1ubuntu0.6) ...
Setting up libpython3.8-dev:amd64 (3.8.10-0ubuntu1~20.04.7) ...
Setting up python3.8-dev (3.8.10-0ubuntu1~20.04.7) ...
Setting up libpython3-dev:amd64 (3.8.2-0ubuntu2) ...
Setting up python3-dev (3.8.2-0ubuntu2) ...
Processing triggers for man-db (2.9.1-1) ...
6. 통과
$ pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-2.1.1.tar.gz (88 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: mysqlclient
Building wheel for mysqlclient (setup.py) ... done
Created wheel for mysqlclient: filename=mysqlclient-2.1.1-cp38-cp38-linux_x86_64.whl size=109214 sha256=e35c5ff9d563012ed6a947716cba8982f042af3d3621b928837cd11193377f11
Stored in directory: {계정 경로}/.cache/pip/wheels/5b/e1/84/a6185eaec318899f59a32d393af7729a0719cd93695d71f9a1
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.1.1