치명적인 오류 : Python.h : 해당 파일 또는 디렉터리가 없습니다.
C 확장 파일을 사용하여 공유 라이브러리를 구축하려고하지만 먼저 아래 명령을 사용하여 출력 파일을 생성해야합니다.
gcc -Wall utilsmodule.c -o Utilc
명령을 실행 한 후 다음 오류 메시지가 표시됩니다.
utilsmodule.c : 1 : 20 : 치명적인 오류 : Python.h : 종료 된 파일 또는 디렉터리 컴파일이 없습니다.
사실 나는 인터넷을 통해 모든 제안 된 해결책을 시도했지만 문제는 여전히 존재합니다. 또한 나는 문제가 없습니다 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
( 오픈 수세 ... )
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
우분투에서는 파이썬 3을 실행하고 있었는데
sudo apt-get install python3-dev
python3에 연결되지 않은 Python 버전을 사용하려면 관련 python3.x-dev 패키지를 설치합니다. 예를 들면 :
sudo apt-get install python3.5-dev
당신이해야 할 두 가지.
Python 용 개발 패키지를 설치합니다. Debian / Ubuntu / Mint의 경우 다음 명령으로 완료됩니다.
sudo apt-get install python-dev
두 번째는 포함 파일이 기본적으로 포함 경로에 있지 않으며 Python 라이브러리가 기본적으로 실행 파일과 연결되어 있지 않다는 것입니다. 다음 플래그를 추가해야합니다 (그에 따라 Python 버전 교체).
-I/usr/include/python2.7 -lpython2.7
즉, 컴파일 명령은 다음과 같아야합니다.
gcc -Wall -I/usr/include/python2.7 -lpython2.7 utilsmodule.c -o Utilc
Raspberry Pi를 사용하는 경우 :
sudo apt-get install python-dev
Fedora에서 Python 2 용으로 실행합니다.
sudo dnf install python2-devel
그리고 Python 3의 경우 :
sudo dnf install python3-devel
tox 를 사용하여 여러 버전의 Python에서 테스트를 실행하는 경우 테스트중인 각 Python 버전에 대해 Python 개발 라이브러리를 설치해야 할 수 있습니다.
sudo apt-get install python2.6-dev
sudo apt-get install python2.7-dev
etc.
Cygwin을 위한 솔루션
사용중인 Python 버전에 따라 패키지 python2-devel
또는python3-devel
을 설치 해야합니다 .
Cygwin.com 에서 32 비트 또는 64 비트 setup.exe
(설치에 따라 다름)를 사용하여 빠르게 설치할 수 있습니다 .
예 ( setup.exe
필요한 경우의 파일 이름 및 Python의 주요 버전 수정 ) :
$ setup.exe -q --packages=python3-devel
명령 줄에서 Cygwin의 패키지를 설치하는 몇 가지 추가 옵션에 대한 다른 답변 을 확인할 수도 있습니다.
In AWS API (centOS) its
yum install python27-devel
For me, changing it to this worked:
#include <python2.7/Python.h>
I found the file /usr/include/python2.7/Python.h
, and since /usr/include
is already in the include path, then python2.7/Python.h
should be sufficient.
You could also add the include path from command line instead - gcc -I/usr/lib/python2.7
(thanks @erm3nda).
AWS EC2 install running python34:
sudo yum install python34-devel
Make sure that the Python dev files come with your OS.
You should not hard code the library and include paths. Instead, use pkg-config, which will output the correct options for your specific system:
$ pkg-config --cflags --libs python2 -I/usr/include/python2.7 -lpython2.7
You may add it to your gcc line:
gcc -Wall utilsmodule.c -o Utilc $(pkg-config --cflags --libs python2)
In my case, what fixed it in Ubuntu was to install the packages libpython-all-dev
(or libpython3-all-dev
if you use Python 3).
It's not the same situation, but it also works for me and now I can use SWIG with Python3.5:
I was trying to compile:
gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/
With Python 2.7 works fine, not with my version 3.5:
existe_wrap.c:147:21: fatal error: Python.h: No existe el archivo o el directorio compilation terminated.
After run in my Ubuntu 16.04 installation:
sudo apt-get install python3-dev # for python3.x installs
Now I can compile without problems Python3.5:
gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/
If you use a virtualenv with a 3.6 python (edge right now), be sure to install the matching python 3.6 dev sudo apt-get install python3.6-dev
, otherwise executing sudo python3-dev
will install the python dev 3.3.3-1, which won't solve the issue.
I also encountered this error when I was installing coolprop in ubuntu.
For ubuntu 16.04 with python 3.6
sudo apt-get install python3.6-dev
If ever this doesn't work try installing/updating gcc
lib.
sudo apt-get install gcc
I managed to solve this issue and generate the .so file in one command
gcc -shared -o UtilcS.so
-fPIC -I/usr/include/python2.7 -lpython2.7 utilsmodule.c
For Python 3.7 and Ubuntu in particular, I needed
sudo apt install libpython3.7-dev
. I think at some point names were changed from pythonm.n-dev
to this.
try apt-file. It is difficult to remember the package name where the missing file resides. It is generic and useful for any package files.
For example:
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#
Now you can make an expert guess as to which one to choose from.
For the OpenSuse comrades out there:
sudo zypper install python3-devel
For CentOS 7:
sudo yum install python36u-devel
I followed the instructions here for installing python3.6 on several VMs: https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-centos-7 and was then able to build mod_wsgi and get it working with a python3.6 virtualenv
This error occurred when I attempted to install ctds on CentOS 7 with Python3.6. I did all the tricks mentioned here including yum install python34-devel
. The problem was Python.h
was found in /usr/include/python3.4m but not in /usr/include/python3.6m
. I tried to use --global-option
to point to include dir (pip3.6 install --global-option=build_ext --global-option="--include-dirs=/usr/include/python3.4m" ctds
). This resulted in a lpython3.6m
not found when linking ctds.
Finally what worked was fixing the development environment for Python3.6 needs to correct with the include and libs.
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 needs to be in your include path for gcc. Whichever version of python is used, for example if it's 3.6, then it should be in /usr/include/python3.6m/Python.h
typically.
Sure python-dev
or libpython-all-dev
are the first thing to (apt
)install
, but if that doesn't help as was my case, I advice you to install the foreign Function Interface packages by sudo apt-get install libffi-dev
and sudo pip install cffi
.
This should help out especially if you see the error as/from c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory
.
If you're using Python 3.6 on Amazon Linux (based on RHEL, but the RHEL answers given here didn't work):
sudo yum install python36-devel
It often appear when you trying to remove python3.5
and install python3.6
.
So when using python3
(which python3 -V
=> python3.6
) to install some packages required python3.5
header will appear this error.
Resolve by install python3.6-dev
module.
Sometimes even after installing python-dev the error persists, Check for the error if it is 'gcc' missing.
First download as stated in https://stackoverflow.com/a/21530768/8687063, then install gcc
For apt (Ubuntu, Debian...):
sudo apt-get install gcc
For yum (CentOS, RHEL...):
sudo yum install gcc
For dnf (Fedora...):
sudo dnf install gcc
For zypper (openSUSE...):
sudo zypper in gcc
For apk (Alpine...):
sudo apk gcc
This means that Python.h
isn't in your compiler's default include paths. Have you installed it system-wide or locally? What's your OS?
You could use the -I<path>
flag to specify an additional directory where your compiler should look for headers. You will probably have to follow up with -L<path>
so that gcc can find the library you'll be linking with using -l<name>
.
You must install the Python development files on your operating system if the Python provided with your operating system does not come with them. The many answers on this question show the myriad ways this can be achieved on different systems.
When you have done so, the problem is telling the compiler where they're located and how to compile against them. Python comes with a program called
python-config
. For compilation, you need the--includes
output and for linking a program against the Python library (embedding Python into your program) the--ldflags
output. Example:gcc -c mypythonprogram.c $(python3-config --includes) gcc -o program mypythonprogram.o $(python3-config --ldflags)
The python-config
program can be named after the Python versions - on Debian, Ubuntu for example these can be named python3-config
or python3.6-config
.
참고URL : https://stackoverflow.com/questions/21530577/fatal-error-python-h-no-such-file-or-directory
'Nice programing' 카테고리의 다른 글
Python이 해석되는 경우 .pyc 파일은 무엇입니까? (0) | 2020.09.27 |
---|---|
Objective-C의 상수 (0) | 2020.09.27 |
JavaScript에서 null과 undefined의 차이점은 무엇입니까? (0) | 2020.09.27 |
그룹화 함수 (tapply, by, 집계) 및 * apply 제품군 (0) | 2020.09.27 |
Android Studio : jar를 라이브러리로 추가 하시겠습니까? (0) | 2020.09.27 |