致命的なエラー: Python.h: そのようなファイルまたはディレクトリはありません 質問する

致命的なエラー: Python.h: そのようなファイルまたはディレクトリはありません 質問する

C 拡張ファイルを使用して共有ライブラリを構築しようとしていますが、まず以下のコマンドを使用して出力ファイルを生成する必要があります。

gcc -Wall utilsmodule.c -o Utilc

コマンドを実行すると、次のエラー メッセージが表示されます。

> utilsmodule.c:1:20: fatal error: Python.h: No such file or directory
compilation terminated.

インターネット上で提案されている解決策をすべて試しましたが、問題は解決しません。 には問題はありませんPython.h。自分のマシン上でファイルを見つけることができました。

ベストアンサー1

Python dev のヘッダー ファイルと静的ライブラリが適切にインストールされていないようです。パッケージ マネージャーを使用して、システム全体にインストールしてください。

apt( Ubuntu、Debian... )の場合:

sudo apt-get install python-dev   # for python2.x installs
sudo apt-get install python3-dev  # for python3.x installs

yum( CentOS、RHEL... )の場合:

sudo yum install python-devel    # for python2.x installs
sudo yum install python3-devel   # for python3.x installs

dnf( Fedora... )の場合:

sudo dnf install python2-devel  # for python2.x installs
sudo dnf install python3-devel  # for python3.x installs

zypper( openSUSE... )の場合:

sudo zypper in python-devel   # for python2.x installs
sudo zypper in python3-devel  # for python3.x installs

apk(アルパイン... )の場合:

# This is a departure from the normal Alpine naming
# scheme, which uses py2- and py3- prefixes
sudo apk add python2-dev  # for python2.x installs
sudo apk add python3-dev  # for python3.x installs

apt-cyg( Cygwin... )の場合:

apt-cyg install python-devel   # for python2.x installs
apt-cyg install python3-devel  # for python3.x installs

重要な注意: python3-dev/devel は、python3 のすべてのマイナー バージョンを自動的にカバーするわけではありません。/ を
インストールする必要がある場合がありますpython3.11-devpython3.11-devel

おすすめ記事