source

치명적인 오류: Python.h: 해당 파일 또는 디렉터리가 없습니다.

itover 2022. 11. 11. 23:31
반응형

치명적인 오류: 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이치노

python dev용 헤더 파일과 정적 라이브러리를 제대로 설치하지 않은 것 같습니다.패키지 관리자를 사용하여 시스템 전체에 설치합니다.

★★★의 apt(우분투, 데비안...)):

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(페도라...):

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

★★★의 zypper(OPEN SUSE...):

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(사이그윈...):

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

주의: python3-dev는 python3의 모든 마이너버전을 자동으로 커버하는 것은 아닙니다.예를 들어 python 3.8을 사용하고 있다면 python3.8-dev를 설치해야 합니다.

Ubuntu에서 Python 3를 실행하고 있었는데

sudo apt-get install python3-dev

python3에 연결되지 않은 Python 버전을 사용하려면 연관된 python3.x-dev 패키지를 설치하십시오.예를 들어 다음과 같습니다.

sudo apt-get install python3.5-dev

특히 Python 3.7Ubuntu에서는

sudo apt install libpython3.7-dev

것 같아요.pythonm.n-dev★★★★★★★★★★★★★★★★★★.

Python 3.6, 3.8~3.10(및 카운트)의 경우도 마찬가지입니다.

sudo apt install libpython3.6-dev

sudo apt install libpython3.8-dev

sudo apt install libpython3.9-dev

sudo apt install libpython3.10-dev

당신이 해야 할 일은 두 가지입니다.

Debian/Ubuntu/Mint의 경우 Python용 개발 패키지를 설치합니다.

sudo apt-get install python-dev

두 번째는 include 파일이 기본적으로 include 경로에 없고 Python 라이브러리가 기본적으로 실행 파일과 링크되지 않는다는 것입니다.다음 플래그를 추가해야 합니다(이에 따라 Python 버전을 바꿉니다).

-I/usr/include/python2.7 -lpython2.7 

즉, 컴파일 명령어는 다음과 같습니다.

gcc -Wall -I/usr/include/python2.7 -lpython2.7  utilsmodule.c -o Utilc 

Fedora에서 Python 2에 대해 다음을 실행합니다.

sudo dnf install python2-devel

Python 3의 경우:

sudo dnf install python3-devel

여러 버전의 Python에서 테스트를 실행하기 위해 tox를 사용하는 경우 테스트 중인 Python의 각 버전에 대해 Python dev 라이브러리를 설치해야 할 수 있습니다.

sudo apt-get install python2.6-dev 
sudo apt-get install python2.7-dev 
etc.

Python dev 파일이 OS와 함께 제공되는지 확인하십시오.

라이브러리의 하드코드에 패스를 포함시키지 마십시오.대신 pkg-config를 사용하면 특정 시스템에 적합한 옵션이 출력됩니다.

$ pkg-config --cflags --libs python2
-I/usr/include/python2.7 -lpython2.7

gcc 라인에 추가할 수 있습니다.

gcc -Wall utilsmodule.c -o Utilc $(pkg-config --cflags --libs python2) 

Cygwin용 솔루션

사용 중인 Python 버전에 따라 또는 패키지를 설치해야 합니다.

32비트 또는 64비트를 사용하여 빠르게 설치할 수 있습니다. setup.exe(설치 내용에 따라 다름)를 참조하십시오.Cygwin.com

)setup.exePython(Python):

$ setup.exe -q --packages=python3-devel

명령줄에서 Cygwin의 패키지를 설치하기 위한 몇 가지 추가 옵션에 대한 다른 답변도 확인할 수 있습니다.

이 설정으로 변경하는 것은, 다음과 같이 동작은 다음과 같습니다.

#include <python2.7/Python.h>

./usr/include/python2.7/Python.h, 그 이후부터, 「」는 「」입니다./usr/include패스에 .그러면 인크루드 패스입니다.python2.7/Python.h충분할 겁니다.

대신 . include 경로는 include를 포함합니다.gcc -I/usr/lib/python2.7(@erm3nda 감사합니다).

AWS API(centOS)의 경우,

yum install python27-devel

python34를 실행하는 AWS EC2 설치:

sudo yum install python34-devel

python과하는 경우 3.6 dev 3.6 python(가상env)을 설치해야 .sudo apt-get install python3.6-dev( 않은 경우 실행)sudo python3-devpython dev 3.3-1은 python dev 3.3-1입니다.

「Ubuntu」를 하는 이었습니다.libpython-all-dev (오류)libpython3-all-devPython 3 の python python python ( Python 3 ) 。

같은 상황은 아니지만 나에게도 효과가 있어 Python3에서 SWIG를 사용할 수 있게 되었습니다.5:

컴파일하려고 했는데:

gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/

Python 2.7에서는 정상적으로 동작하지만 버전 3.5에서는 동작하지 않습니다.

existe_wrap.c:147:21:치명적 오류:Python.h:no existe el archivo o el directorio 컴파일이 종료되었습니다.

Ubuntu 16.04 설치 실행 후:

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

이것으로 Python3를 문제없이 컴파일 할 수 있게 되었습니다.5:

gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/

이 문제를 해결하고 하나의 명령어로 .so 파일을 생성할 수 있었습니다.

gcc -shared -o UtilcS.so
-fPIC -I/usr/include/python2.7 -lpython2.7  utilsmodule.c

우분투에서 coolprop를 설치할 때도 이 오류가 발생하였습니다.

python 3.6을 사용하는 ubuntu 16.04의 경우

sudo apt-get install python3.6-dev

하지 않는 는, 해 주세요.gcclib.lib.

sudo apt-get install gcc

압트파일을 시험해 보다누락된 파일이 있는 패키지 이름을 기억하는 것은 어렵습니다.이 파일은 일반적이며 모든 패키지 파일에 유용합니다.

예를 들어 다음과 같습니다.

root@ubuntu234:~/auto# apt-file search --regexp '/Python.h$'
pypy-dev: /usr/lib/pypy/include/Python.h
python2.7-dbg: /usr/include/python2.7_d/Python.h
python2.7-dev: /usr/include/python2.7/Python.h
python3.2-dbg: /usr/include/python3.2dmu/Python.h
python3.2-dev: /usr/include/python3.2mu/Python.h
root@ubuntu234:~/auto# 

이제 당신은 어떤 것을 선택해야 할지 전문가 추측을 할 수 있습니다.

센트의 경우OS 7:

sudo yum install python36u-devel

몇 개의 VM에 python3.6을 인스톨 하는 순서에 따라서, https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-centos-7 를 실행해, mod_wsgi 를 빌드 해 python3.6 virtualenv 로 동작시킬 수 있었습니다.

OpenSuse 동지 여러분:

sudo zypper install python3-devel

이 문제는 다른 버전의 Python이 설치되어 있고 시스템의 pip이 아닌 pip을 사용하는 경우에도 발생할 수 있습니다.이 경우 비시스템 pip은 올바른 버전의 Python 헤더를 찾을 수 없습니다.

애플리케이션에 번들된 Python용 패키지를 pip 설치하려고 할 때 발생하였습니다.시스템의 python이 아니기 때문에 apt install pythonXX-dev는 동작하지 않았습니다.

이 경우 해결책은 올바른 python 헤더를 찾는 것입니다.

find / -iname 'Python.h'

출력에는 시스템 python 헤더가 표시됩니다.또, 이하와 같이, 희망하는 헤더가 표시됩니다.

/usr/include/python3.7m/Python.h
/usr/include/python3.6m/Python.h
/home/ubuntu/workspace/blender-git/lib/linux_centos7_x86_64/python/include/python3.7m/Python.h
/home/ubuntu/miniconda3/pkgs/python-3.8.5-h7579374_1/include/python3.8/Python.h
/home/ubuntu/miniconda3/pkgs/python-3.7.0-h6e4f718_3/include/python3.7m/Python.h
/home/ubuntu/miniconda3/include/python3.8/Python.h
/home/ubuntu/miniconda3/envs/sim/include/python3.7m/Python.h
/home/ubuntu/src/blender-deps/Python-3.7.7/Include/Python.h
/opt/lib/python-3.7.7/include/python3.7m/Python.h

그런 다음 pip으로 호출할 때 gcc에서 사용하는 컴파일러 플래그를 설정할 수 있습니다.저는 /home/ubuntu/workspace/blender-git/lib/linux_centos7_x86_64/python/include/python3.7m/Python.h였습니다.그래서 저는 다음과 같이 했습니다.

export CPPFLAGS=-I/home/ubuntu/src/blender-deps/Python-3.7.7/Include
pip install <package>

Python 3.6을 Amazon Linux에서 사용하는 경우(RHEL 기반이지만 여기에 제시된 RHEL 답변이 작동하지 않음):

sudo yum install python36-devel

여기 또 다른 해결책이 있습니다. 왜냐하면 이 솔루션들 중 어느 것도 제게는 효과가 없었기 때문입니다.참고로, 저는 지금pip installPython 3.6용 Amazon Linux AMI 기반 Docker 이미지에 있습니다.

비도커 솔루션:

# Install python3-devel like everyone says
yum -y install python36-devel.x86_64

# Find the install directory of `Python.h`
rpm -ql python36-devel.x86_64 | grep -i "Python.h"

# Forcefully add it to your include path
C_INCLUDE_PATH='/usr/include/python3.6m'
export C_INCLUDE_PATH

도커 솔루션:

# Install python3-devel like everyone says
RUN yum -y install python36-devel.x86_64

# Find the install directory of `Python.h`, for me it was /usr/include/python3.6m
RUN rpm -ql python36-devel.x86_64 | grep -i "Python.h" && fake_command_so_docker_fails_and_shows_us_the_output

# Since the previous command contains a purposeful error, remove it before the next run

# Forcefully add it to your include path
ARG C_INCLUDE_PATH='/usr/include/python3.6m'

메모: C++ 컴파일 시 오류가 발생할 경우CPLUS_INCLUDE_PATH.

또는 다른 도커 이미지를 사용할 수도 있습니다.예를 들어 설치하려고 했습니다.asyncpg~=0.24.0python:3.9.4-slim이 에러에 의해, 표시된 것과 같은 에러가 발생했습니다.하지만 이미지를 업데이트 했을 때python:3, 잘 작동했습니다.

  1. 운영체제와 함께 제공된 Python이 함께 제공되지 않는 경우 Python 개발 파일을 운영체제에 설치해야 합니다.이 질문에 대한 많은 답변은 다양한 시스템에서 이를 달성할 수 있는 수많은 방법을 보여줍니다.

  2. 이렇게 하면 컴파일러에 컴파일러의 위치와 컴파일 방법을 알려주는 것이 문제입니다.Python은 다음과 같은 프로그램을 제공합니다.python-config컴파일을 위해서는--includes출력 및 Python 라이브러리에 대한 프로그램 링크(Python을 프로그램에 포함)를 위해.--ldflags산출량.예:

    gcc -c mypythonprogram.c $(python3-config --includes)
    gcc -o program mypythonprogram.o $(python3-config --ldflags)
    

python-config프로그램 이름은 Python 버전 이름을 따서 지정할 수 있습니다. 예를 들어 Debian, Ubuntu에서는 이러한 이름을 지정할 수 있습니다.python3-config또는python3.6-config.

그럼요.python-dev또는libpython-all-dev(의 첫 번째)apt)install하지만, 제 경우와 같이 도움이 되지 않는다면, 저는 당신이 다음 방법으로 외부 기능 인터페이스 패키지를 설치하는 것을 추천합니다.sudo apt-get install libffi-dev ★★★★★★★★★★★★★★★★★」sudo pip install cffi.

, 에러가, , 에러, 했을 경우에 도움이 됩니다.c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory.

Python을 찾아보세요.h:

gemfield@ThinkPad-X1C:~$ locate Python.h
/home/gemfield/anaconda3/include/python3.7m/Python.h
/home/gemfield/anaconda3/pkgs/python-3.7.6-h0371630_2/include/python3.7m/Python.h
/usr/include/python3.8/Python.h

찾을 수 없는 경우 python-dev 또는 python3-dev를 설치합니다.그렇지 않으면 컴파일러의 올바른 헤더 경로를 포함합니다.

g++ -I/usr/include/python3.8 ...

우분투에 있어요.일부 답변에서 권장한 대로 모든 패키지를 설치했습니다.

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

난 여전히 문제가 있었어, 대사:

#include "Python.h"

그 외의 경우는, 수동으로 편집할 수 있습니다만, 이것은 좋지 않은 방법입니다.비밀은 이제 알겠어요 사이튼 소스코드에서 나온 거예요파일을 가지고 있어요.오류 없이 컴파일할 수 있습니다.그게 파일이에요.PYTON을 python 버전 python/python3으로 변경합니다.FILE을 c-filename으로 변경합니다.makefile 파일의 이름은 Makefile이어야 합니다.다음 명령으로 파일을 실행합니다.

make all

독립 실행형 Cython 프로그램을 만들기 위한 Makefile

    FILE := file.c
    PYTHON := python3
    PYVERSION := $(shell $(PYTHON) -c "import sys;                     
    print(sys.version[:3])")
    PYPREFIX := $(shell $(PYTHON) -c "import sys; print(sys.prefix)")

    INCDIR := $(shell $(PYTHON) -c "from distutils import sysconfig; 
    print(sysconfig.get_python_inc())")
    PLATINCDIR := $(shell $(PYTHON) -c "from distutils import 
    sysconfig; print(sysconfig.get_python_inc(plat_specific=True))")
    LIBDIR1 := $(shell $(PYTHON) -c "from distutils import sysconfig; 
    print(sysconfig.get_config_var('LIBDIR'))")
    LIBDIR2 := $(shell $(PYTHON) -c "from distutils import sysconfig; 
    print(sysconfig.get_config_var('LIBPL'))")
    PYLIB := $(shell $(PYTHON) -c "from distutils import sysconfig; 
    print(sysconfig.get_config_var('LIBRARY')[3:-2])")

    CC := $(shell $(PYTHON) -c "import distutils.sysconfig; 
    print(distutils.sysconfig.get_config_var('CC'))")
    LINKCC := $(shell $(PYTHON) -c "import distutils.sysconfig; 
    print(distutils.sysconfig.get_config_var('LINKCC'))")
    LINKFORSHARED := $(shell $(PYTHON) -c "import distutils.sysconfig; 
    print(distutils.sysconfig.get_config_var('LINKFORSHARED'))")
    LIBS := $(shell $(PYTHON) -c "import distutils.sysconfig; 
    print(distutils.sysconfig.get_config_var('LIBS'))")
    SYSLIBS :=  $(shell $(PYTHON) -c "import distutils.sysconfig; 
    print(distutils.sysconfig.get_config_var('SYSLIBS'))")

    .PHONY: paths all clean test

    paths:
        @echo "PYTHON=$(PYTHON)"
        @echo "PYVERSION=$(PYVERSION)"
        @echo "PYPREFIX=$(PYPREFIX)"
        @echo "INCDIR=$(INCDIR)"
        @echo "PLATINCDIR=$(PLATINCDIR)"
        @echo "LIBDIR1=$(LIBDIR1)"
        @echo "LIBDIR2=$(LIBDIR2)"
        @echo "PYLIB=$(PYLIB)"
        @echo "CC=$(CC)"
        @echo "LINKCC=$(LINKCC)"
        @echo "LINKFORSHARED=$(LINKFORSHARED)"
        @echo "LIBS=$(LIBS)"
        @echo "SYSLIBS=$(SYSLIBS)"

    $(FILE:.c=): $(FILE:.c=.o)
        $(LINKCC) -o $@ $^ -L$(LIBDIR1) -L$(LIBDIR2) -l$(PYLIB)         
    $(LIBS) $(SYSLIBS) $(LINKFORSHARED)

    $(FILE:.c=.o): $(FILE)
        $(CC) -c $^ -I$(INCDIR) -I$(PLATINCDIR)

    all: $(FILE:.c=)

를 설치하려고 때 했습니다.Python 3.6을 탑재한 OS 7여기에 언급된 모든 속임수를 다 썼는데yum install python34-devel★★★★★★★★★★★★★★★★★★.Python.h되었습니다./usr/include/python3.4m but not in /usr/include/python3.6m사용하려고 했습니다.--global-optionpip3.6 install --global-option=build_ext --global-option="--include-dirs=/usr/include/python3.4m" ctds 결과, 「 」가 되었습니다lpython3.6mctds를 링크할 때 수 .

마지막으로 include와 libs를 사용하여 Python3.6의 개발 환경을 수정했습니다.

yum -y install https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/python36u-libs-3.6.3-1.ius.centos7.x86_64.rpm

Python.h' gcc'에는 "Python.h' gcc'가 포함됩니다.을 사용하든,를 들어.6인 , 비단뱀, 비단뱀, 비단뱀 3.6, 비단뱀이다./usr/include/python3.6m/Python.h일반적으로.

하려고 할 때 .python3.5를 인스톨 합니다.python3.6.

래서사 so를 사용할 때python3인가)python3 -V> =>python3.6를 , 몇개의 가 필요했습니다.python3.5헤더에 이 에러가 표시됩니다.

「」를 인스톨 해 합니다.python3.6-dev★★★★★★ 。

python-dev를 설치한 후에도 오류가 지속될 수 있습니다.gcc가 누락된 경우 오류를 확인하십시오.

https://stackoverflow.com/a/21530768/8687063,에 기재되어 있는 대로 먼저 다운로드 후 gcc를 설치합니다.

(우분투, 데비안...)를 위해):

sudo apt-get install gcc

yum(CentOS, RHEL...):

sudo yum install gcc

dnf의 경우(Fedora...):

sudo dnf install gcc

zypper(open SUSE...):

sudo zypper in gcc

apk의 경우(Alpine...)):

sudo apk gcc

, ,,Python.hinclude paths include default는 시스템 로컬 중 어느 ?시스템 전체에 설치했습니까, 아니면 로컬에 설치했습니까?OS os os os os os os?

해서 '아까불까불까불까불까불까불까불까불까불까불까불까불까불까불까불까요?-I<path>플래그를 사용하여 컴파일러가 헤더를 검색할 추가 디렉토리를 지정합니다. 업을 할 것 같아요.-L<path>는 gcc를 사용해서 수 .-l<name>.

언급URL : https://stackoverflow.com/questions/21530577/fatal-error-python-h-no-such-file-or-directory

반응형