2. AWS Linux 2 에서 pip install for MariaDB 수행할 때 버그 해결

,

AWS Linux2 EC2에서 python 프로그램을 수행한다.
MariaDB를 이용해서 수행하려 한다. 서비스 수행과 관련된 라이브러리를 AWS Linux2에 설치해야 한다.

버전을 10.5로 유지한다면 가능하겠지만, python pip package를 해당 버전에 맞게 낮춰야 한다.
11.2 를 기준으로 로컬에서 작업하다보니 11.2로 AWS EC2를 설정하기로 했다.

그러다 삽질을 했다.
지난 블로그 참고

#1. pip install -r requirements.txt

Collecting bcrypt
  Using cached bcrypt-4.1.2-cp39-abi3-manylinux_2_28_x86_64.whl (698 kB)
Collecting bs4
  Using cached bs4-0.0.2-py2.py3-none-any.whl (1.2 kB)
Collecting fastapi
  Using cached fastapi-0.109.2-py3-none-any.whl (92 kB)
Collecting finance-datareader
  Using cached finance_datareader-0.9.70-py3-none-any.whl (24 kB)
Collecting jinja2
  Using cached Jinja2-3.1.3-py3-none-any.whl (133 kB)
Collecting mojito2
  Using cached mojito2-0.1.6-py3-none-any.whl (14 kB)
Collecting mariadb
  Using cached mariadb-1.1.10.tar.gz (84 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: /home/ec2-user/handy_stock_server/venv/bin/python /home/ec2-user/handy_stock_server/venv/lib64/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmp7ckbildr
       cwd: /tmp/pip-install-rwnum8ns/mariadb_7477d466de1d4b9790887d17a7ee27b1
  Complete output (30 lines):
  /bin/sh: line 1: mariadb_config: command not found
  Traceback (most recent call last):
    File "/home/ec2-user/handy_stock_server/venv/lib64/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
      main()
    File "/home/ec2-user/handy_stock_server/venv/lib64/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/home/ec2-user/handy_stock_server/venv/lib64/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
      return hook(config_settings)
    File "/tmp/pip-build-env-0spwsnhb/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
    File "/tmp/pip-build-env-0spwsnhb/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
      self.run_setup()
    File "/tmp/pip-build-env-0spwsnhb/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 480, in run_setup
      super().run_setup(setup_script=setup_script)
    File "/tmp/pip-build-env-0spwsnhb/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 311, in run_setup
      exec(code, locals())
    File "<string>", line 27, in <module>
    File "/tmp/pip-install-rwnum8ns/mariadb_7477d466de1d4b9790887d17a7ee27b1/mariadb_posix.py", line 62, in get_config
      cc_version = mariadb_config(config_prg, "cc_version")
    File "/tmp/pip-install-rwnum8ns/mariadb_7477d466de1d4b9790887d17a7ee27b1/mariadb_posix.py", line 28, in mariadb_config
      raise EnvironmentError(
  OSError: mariadb_config not found.

  This error typically indicates that MariaDB Connector/C, a dependency which
  must be preinstalled, is not found.
  If MariaDB Connector/C is not installed, see installation instructions
  If MariaDB Connector/C is installed, either set the environment variable
  MARIADB_CONFIG or edit the configuration file 'site.cfg' to set the
   'mariadb_config' option to the file location of the mariadb_config utility.

  ----------------------------------------

이버그를 해결하기 위해서는 yum에서 다음의 패키지를 추가로 설치해야 한다.

sudo yum install MariaDB-devel

이제 MariaDB 개발 할 수 있것다.

#2. 또 에러남

  ERROR: Command errored out with exit status 1:
   command: /home/ec2-user/handy_stock_server/venv/bin/python /home/ec2-user/handy_stock_server/venv/lib64/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmpyluekoip
       cwd: /tmp/pip-install-6nizpyr8/mariadb_233ebac092da4b9bab1741cfe3fa48eb
  Complete output (32 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-cpython-39
  creating build/lib.linux-x86_64-cpython-39/mariadb
  copying mariadb/__init__.py -> build/lib.linux-x86_64-cpython-39/mariadb
  copying mariadb/connectionpool.py -> build/lib.linux-x86_64-cpython-39/mariadb
  copying mariadb/connections.py -> build/lib.linux-x86_64-cpython-39/mariadb
  creating build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/__init__.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/CAPABILITY.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/CURSOR.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/ERR.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/FIELD_FLAG.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/EXT_FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/INDICATOR.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/INFO.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/STATUS.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/TPC_STATE.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/cursors.py -> build/lib.linux-x86_64-cpython-39/mariadb
  copying mariadb/dbapi20.py -> build/lib.linux-x86_64-cpython-39/mariadb
  copying mariadb/field.py -> build/lib.linux-x86_64-cpython-39/mariadb
  copying mariadb/release_info.py -> build/lib.linux-x86_64-cpython-39/mariadb
  running build_ext
  building 'mariadb._mariadb' extension
  creating build/temp.linux-x86_64-cpython-39
  creating build/temp.linux-x86_64-cpython-39/mariadb
  gcc -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -ftree-vectorize -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -ftree-vectorize -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -ftree-vectorize -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPY_MARIADB_MAJOR_VERSION=1 -DPY_MARIADB_MINOR_VERSION=1 -DPY_MARIADB_PATCH_VERSION=10 -DPY_MARIADB_PRE_RELEASE_SEGMENT=\"None\" -DPY_MARIADB_PRE_RELEASE_NR=\"0\" -DPY_MARIADB_POST_RELEASE_SEGMENT=\"None\" -DPY_MARIADB_POST_RELEASE_NR=\"0\" -I/usr/include/mysql -I/usr/include/mysql/mysql -I./include -I/home/ec2-user/handy_stock_server/venv/include -I/usr/include/python3.9 -c mariadb/mariadb.c -o build/temp.linux-x86_64-cpython-39/mariadb/mariadb.o -DDEFAULT_PLUGINS_SUBDIR=\"/usr/lib64/mysql/plugin\"
  error: command 'gcc' failed: No such file or directory
  ----------------------------------------
  ERROR: Failed building wheel for mariadb
Failed to build mariadb
ERROR: Could not build wheels for mariadb, which is required to install pyproject.toml-based projects

GCC가 깔려있지 않다고 함. 깔아보자 GCC

#3. yum install gcc

Building wheels for collected packages: mariadb
  Building wheel for mariadb (pyproject.toml) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/ec2-user/handy_stock_server/venv/bin/python /home/ec2-user/handy_stock_server/venv/lib64/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /tmp/tmpo1t9unkh
       cwd: /tmp/pip-install-1rwf240j/mariadb_f97855aeb1de47b5ad2199b34a952987
  Complete output (37 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-cpython-39
  creating build/lib.linux-x86_64-cpython-39/mariadb
  copying mariadb/__init__.py -> build/lib.linux-x86_64-cpython-39/mariadb
  copying mariadb/connectionpool.py -> build/lib.linux-x86_64-cpython-39/mariadb
  copying mariadb/connections.py -> build/lib.linux-x86_64-cpython-39/mariadb
  creating build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/__init__.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/CAPABILITY.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/CURSOR.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/ERR.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/FIELD_FLAG.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/EXT_FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/INDICATOR.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/INFO.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/STATUS.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/constants/TPC_STATE.py -> build/lib.linux-x86_64-cpython-39/mariadb/constants
  copying mariadb/cursors.py -> build/lib.linux-x86_64-cpython-39/mariadb
  copying mariadb/dbapi20.py -> build/lib.linux-x86_64-cpython-39/mariadb
  copying mariadb/field.py -> build/lib.linux-x86_64-cpython-39/mariadb
  copying mariadb/release_info.py -> build/lib.linux-x86_64-cpython-39/mariadb
  running build_ext
  building 'mariadb._mariadb' extension
  creating build/temp.linux-x86_64-cpython-39
  creating build/temp.linux-x86_64-cpython-39/mariadb
  gcc -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -ftree-vectorize -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -ftree-vectorize -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -ftree-vectorize -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPY_MARIADB_MAJOR_VERSION=1 -DPY_MARIADB_MINOR_VERSION=1 -DPY_MARIADB_PATCH_VERSION=10 -DPY_MARIADB_PRE_RELEASE_SEGMENT=\"None\" -DPY_MARIADB_PRE_RELEASE_NR=\"0\" -DPY_MARIADB_POST_RELEASE_SEGMENT=\"None\" -DPY_MARIADB_POST_RELEASE_NR=\"0\" -I/usr/include/mysql -I/usr/include/mysql/mysql -I./include -I/home/ec2-user/handy_stock_server/venv/include -I/usr/include/python3.9 -c mariadb/mariadb.c -o build/temp.linux-x86_64-cpython-39/mariadb/mariadb.o -DDEFAULT_PLUGINS_SUBDIR=\"/usr/lib64/mysql/plugin\"
  In file included from mariadb/mariadb.c:21:
  ./include/mariadb_python.h:21:10: fatal error: Python.h: No such file or directory
     21 | #include "Python.h"
        |          ^~~~~~~~~~
  compilation terminated.
  error: command '/usr/bin/gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for mariadb
Failed to build mariadb
ERROR: Could not build wheels for mariadb, which is required to install pyproject.toml-based projects

python3-devel이 없어서 컴파일이 안된다.

sudo yum install python3-devel

#4. 드디어 빌드 성공

이제 크론잡을 하자.
aws-ec2-스케쥴-배치-업무-설정-with-crontab

전체 과정 블로그 /aws-ec2-mariadb-환경-설정