LoginSignup
3
0

More than 3 years have passed since last update.

Alpine Linuxでpip install mysqlclientするのにハマった時のメモ

Last updated at Posted at 2021-03-10

環境

  • Alpine Linux 3.13
  • Python3

何が起きたか

mysqlclientをインストールしたくて以下のコマンドを実行したところ、OSError: mysql_config not found.と怒られてしまった。

localhost:~# pip install mysqlclient

解決方法

1. mariadb-devとpython3-devをインストール

localhost:~# apk add python3-dev mariadb-dev

参考資料ではlibmysqlclient-devとあるが、見当たらないのでapk searchで探してそれっぽいもの(mariadb-dev)を見つけた。
改めてpip install mysqlclientを実行したところ、今度は以下のように怒られてしまった。

localhost:~# pip install mysqlclient

Collecting mysqlclient
  Using cached mysqlclient-2.0.3.tar.gz (88 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-t0g2ij73/mysqlclient_1f7595becde34cc9a57c20ae31140ee9/setup.py'"'"'; __file__='"'"'/tmp/pip-install-t0g2ij73/mysqlclient_1f7595becde34cc9a57c20ae31140ee9/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-d25ff_vg/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python3.8/mysqlclient
         cwd: /tmp/pip-install-t0g2ij73/mysqlclient_1f7595becde34cc9a57c20ae31140ee9/

# 中略

 unable to execute 'gcc': No such file or directory
    error: command 'gcc' failed with exit status 1

# 以下略

2. gccをインストール

gccが実行できないよ!とのことなのでインストールする。

localhost:~# apk add gcc

そして実行。

localhost:~# pip install mysqlclient

Collecting mysqlclient
  Using cached mysqlclient-2.0.3.tar.gz (88 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-b19o0790/mysqlclient_d995157d7485408da5d33e0f23e8d465/setup.py'"'"'; __file__='"'"'/tmp/pip-install-b19o0790/mysqlclient_d995157d7485408da5d33e0f23e8d465/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-y7qc2y_l/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python3.8/mysqlclient
         cwd: /tmp/pip-install-b19o0790/mysqlclient_d995157d7485408da5d33e0f23e8d465/

# 中略

In file included from MySQLdb/_mysql.c:29:
    /usr/include/mysql/mysql.h:38:10: fatal error: sys/types.h: No such file or directory
       38 | #include <sys/types.h>
          |          ^~~~~~~~~~~~~
    compilation terminated.
    error: command 'gcc' failed with exit status 1

# 以下略

3. libc-devをインストール

sys/type.hがないとのことだったので、調べたところこんな記事が見つかった。これによると、libc6-dev-i386なるものをインストールすれば良いらしいが、これまた見当たらないので例によってapk searchで探してみると、またそれっぽいのが見つかったのでインストールした。

localhost:~# apk add libc-dev

(1/2) Installing musl-dev (1.2.2-r0)
(2/2) Installing libc-dev (0.7.2-r3)
OK: 413 MiB in 179 packages

そして3度目の正直。

localhost:~# apk add python3-dev

(1/1) Installing python3-dev (3.8.7-r1)
Executing busybox-1.32.1-r3.trigger
OK: 452 MiB in 180 packages
localhost:~# pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.0.3.tar.gz (88 kB)
Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed.
Installing collected packages: mysqlclient
    Running setup.py install for mysqlclient ... done
Successfully installed mysqlclient-2.0.3

できた。

3
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0