简体   繁体   English

致命错误:安装时找不到“Python.h”文件 opencv

[英]fatal error: 'Python.h' file not found while installing opencv

I am trying to get opencv 3.1 installed for Python on my Mac OS X 10.10.5 I'm following the steps as outlined here - http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2.7-on-osx/我正在尝试在我的 Mac OS X 10.10.5 上为 Python 安装 opencv 3.1 我正在按照此处概述的步骤进行操作 - http://www.pyimagesearch.com/2015/06/15/install-opencv-3- 0-和-python-2.7-on-osx/

When I actually try installing opencv after all the setup, I get the following error:当我在完成所有设置后实际尝试安装 opencv 时,出现以下错误:

.../opencv/modules/python/src2/cv2.cpp:6:10: fatal error: 
  'Python.h' file not found
 #include <Python.h>
          ^

I looked around StackOverflow and found that most people facing this issue are using Anaconda, which is not my case.我环顾了 StackOverflow,发现大多数面临此问题的人都在使用 Anaconda,而我的情况并非如此。 It would be great if someone could point me in the right direction to get this fixed.如果有人能指出正确的方向来解决这个问题,那就太好了。

Thanks,谢谢,

If Python.h is not found while making one of the *.cpp files, set the following ENV variable如果在制作 *.cpp 文件之一时未找到 Python.h,请设置以下 ENV 变量

export CPLUS_INCLUDE_PATH=/System/Library/Frameworks/Python.framework/Headers

Please check the existence of the path in your system and make sure that Python.h is there.请检查系统中路径是否存在,并确保存在 Python.h。

I'm using El Capitan but I don't think there should be much difference in the path to the Python header.我正在使用El Capitan但我认为 Python 标头的路径应该没有太大区别。 I find mine at:我在以下位置找到我的:

/System/Library/Frameworks/Python.framework/Headers/Python.h

You could try and run:你可以尝试运行:

export C_INCLUDE_PATH=/System/Library/Frameworks/Python.framework/Headers

then try the remaining steps.然后尝试剩余的步骤。

Run

brew install python

or或者

brew upgrade python

after doing this, everything(vim in my case) you want to install will be success.执行此操作后,您要安装的所有内容(在我的情况下为 vim)都会成功。

I had the same problem on OSX, fixed by setting the CPLUS_INCLUDE_PATH environment variable.我在 OSX 上遇到了同样的问题,通过设置 CPLUS_INCLUDE_PATH 环境变量来解决。 Was also building in an anaconda environment which might have complicated things.还在可能有复杂事情的 anaconda 环境中构建。

export CPLUS_INCLUDE_PATH=~/anaconda/envs/py27/include/python2.7

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=~/anaconda/envs/py27/share \
    -D PYTHON2_PACKAGES_PATH=~/anaconda/envs/py27/lib/python2.7/site-packages \
    -D PYTHON2_LIBRARY=~/anaconda/envs/py27/bin/python \
    -D PYTHON_EXECUTABLE=~/anaconda/envs/py27/bin/python \
    -D PYTHON2_INCLUDE_DIR=~/anaconda/envs/py27/include/python2.7 \
    -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON \
    -D BUILD_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..

This question seems to be regarding the default Python2 integrated into the macOS, for which the Python.h header file is in the address:这个问题似乎是关于集成到macOS的默认Python2,其Python.h头文件在地址中:

/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h

the Python version might change depending on the macOS version you are using though. Python 版本可能会根据您使用的 macOS 版本而变化。 However, if you have installed Python3 using Hombrew, as probably you should then you might find the header file in a path like:但是,如果您使用 Hombrew 安装了 Python3,那么您可能应该在以下路径中找到头文件:

/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h

depending on the version of Python3 your brew has installed for you.根据您的brew为您安装的 Python3 版本。 Again there are many other possibilities to get Python on mac (eg, anaconda, intel python, pypy,... you name it).同样,在 mac 上使用 Python 有很多其他的可能性(例如,anaconda、intel python、pypy,...你能想到的)。 The best way to find the path to a specific Python.h is to search your entire device with:找到特定Python.h路径的最佳方法是使用以下命令搜索整个设备:

sudo find / -iname "Python.h"

Then you can run the command然后你可以运行命令

export C_INCLUDE_PATH=<path/to/the/specific/header/file>

in your bash terminal, or add it to the ~/.bash_profile to have it there permanently.在您的 bash 终端中,或将其添加到~/.bash_profile以使其永久存在。

You may wanna also check the MakeFile (or other tooling the software uses eg, cmake...) to see what versions of Python.h it is expecting and in what locations.您可能还想检查 MakeFile(或该软件使用的其他工具,例如 cmake...)以查看它期望的Python.h版本以及在哪些位置。 it is expecting it.它正在期待它。

First, you have to check and make sure you have installed the python using brew and you are using the system python lib binary.首先,您必须检查并确保您已经使用 brew 安装了 python 并且您正在使用系统 python lib 二进制文件。 That's was mentioned in the blog.这是博客里提到的。

Second, the python version in the cmake command must match what brew has installed for you.其次,cmake 命令中的 python 版本必须与 brew 为您安装的版本相匹配。 You should double check that.你应该仔细检查一下。

Yes, revise the paths used in the cmake command.是的,修改 cmake 命令中使用的路径。 They must exist in your filesystem.它们必须存在于您的文件系统中。 In my case, I have installed python 3.5 and the original documentation uses python 3.4.就我而言,我安装了 python 3.5,原始文档使用 python 3.4。

My approach was different, but it's basically what Jonathan Lau mentioned.我的方法不同,但基本上就是Jonathan Lau 提到的。

I used pyenv and conda and changed my python lib path which caused the problem.我使用了 pyenv 和 conda 并更改了导致问题的 python lib 路径。 To solve it, here's what I did为了解决它,这就是我所做的

  1. Commented out PATH setting for pyenv in .bashrc在 .bashrc 中注释掉 pyenv 的 PATH 设置
  2. Restart terminal and brew install whatever you need (vim in my case)重新启动终端并 brew install 你需要的任何东西(在我的例子中是 vim)
  3. Change .bashrc back将 .bashrc 改回

I fixed my problem by installing python2.7, apparently it was compiling using python 3.4.我通过安装 python2.7 解决了我的问题,显然它是使用 python 3.4 编译的。 So I did the following:所以我做了以下事情:

brew install python@2
brew link python@2

I solved this problem on mac os 12.2.1 like this: export CPPFLAGS="-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7" and then pip install...我在 mac os 12.2.1 上解决了这个问题,如下所示: export CPPFLAGS="-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7"然后pip install...

for me it worked to upgrade pip before trying to install pycurl :对我来说,它在尝试安装 pycurl 之前升级了pycurl

pip install --upgrade pip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:安装ouchapp时找不到“ Python / Python.h”文件 - fatal error: 'Python/Python.h' file not found while installing couchapp make pycaffe致命错误:找不到&#39;Python.h&#39;文件 - make pycaffe fatal error: 'Python.h' file not found 致命错误:Python.h:没有这样的文件或目录 - fatal error: Python.h: No such file or directory 无法在 Mac 上安装 async-sqlalchemy(致命错误:找不到“Python.h”文件#include“Python.h”) - Can not install async-sqlalchemy on Mac (fatal error: 'Python.h' file not found #include "Python.h") 在 anaconda3 中安装 openCV - Python.h:没有那个文件或目录 - Installing openCV in anaconda3 - Python.h: No such file or directory C 致命错误:Python.h:没有这样的文件或目录#include<Python.h> - C fatal error: Python.h: No such file or directory #include <Python.h> Ubuntu,致命错误:Python.h: No such file or directory #include<Python.h> - Ubuntu, fatal error: Python.h: No such file or directory #include <Python.h> Cython致命错误:Python.h没有这样的文件或目录 - Cython Fatal Error: Python.h No such file or directory 安装 Watchman 时找不到“Python.h”文件 - Can't find “Python.h” file while installing Watchman 在 cmake 失败的情况下安装 OPENCV。 Python.h - Installing OPENCV with cmake failing. Python.h
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM