CentOS7にPython3を入れたが_ctypesモジュールが存在しなくpipできない

pipでライブラリをインストールしようと思ってもエラーを吐いたので解決方法をメモ

$pip install certbot
Collecting certbot
  Using cached certbot-1.27.0-py3-none-any.whl (272 kB)
Collecting configobj>=5.0.6
  Downloading configobj-5.0.6.tar.gz (33 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [1 lines of output]
      ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
      [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.

versionを確認してみる

$easy_install --version
Traceback (most recent call last):
  File "/root/.pyenv/versions/3.7.13/bin/easy_install", line 5, in <module>
    from setuptools.command.easy_install import main
  File "/root/.pyenv/versions/3.7.13/lib/python3.7/site-packages/setuptools/__init__.py", line 19, in <module>
    from setuptools.dist import Distribution
  File "/root/.pyenv/versions/3.7.13/lib/python3.7/site-packages/setuptools/dist.py", line 34, in <module>
    from setuptools import windows_support
  File "/root/.pyenv/versions/3.7.13/lib/python3.7/site-packages/setuptools/windows_support.py", line 2, in <module>
    import ctypes
  File "/root/.pyenv/versions/3.7.13/lib/python3.7/ctypes/__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

どうやら_ctypesというモジュールがないらしい。
必要なライブラリを入れてみる

$yum install libffi-devel

再度pythonをインストールして実行

$pyenv install 3.7.13

$pip install certbot

インストールできた。

参考にしたサイト
https://github.com/pypa/packaging-problems/issues/573
https://qiita.com/nakamura_hikaru/items/d9167d523b8b12839709

コメント

タイトルとURLをコピーしました