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/
When I actually try installing opencv after all the setup, I get the following error:
.../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. 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
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.
I'm using El Capitan
but I don't think there should be much difference in the path to the Python header. 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.
I had the same problem on OSX, fixed by setting the CPLUS_INCLUDE_PATH environment variable. Was also building in an anaconda environment which might have complicated things.
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:
/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. However, if you have installed Python3 using Hombrew, as probably you should then you might find the header file in a path like:
/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. Again there are many other possibilities to get Python on mac (eg, anaconda, intel python, pypy,... you name it). The best way to find the path to a specific Python.h
is to search your entire device with:
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.
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. 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. That's was mentioned in the blog.
Second, the python version in the cmake command must match what brew has installed for you. You should double check that.
Yes, revise the paths used in the cmake command. They must exist in your filesystem. In my case, I have installed python 3.5 and the original documentation uses python 3.4.
My approach was different, but it's basically what Jonathan Lau mentioned.
I used pyenv and conda and changed my python lib path which caused the problem. To solve it, here's what I did
I fixed my problem by installing python2.7, apparently it was compiling using 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...
for me it worked to upgrade pip before trying to install pycurl
:
pip install --upgrade pip
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.