My Environment:
1- MacOs catalina.
2- VScode "Visual Studio Code"
3- PlatformIO extension (for Arduino Development in C/C++) mainly C++
4- Python3 and Python2 are both installed on my mac.
The Problem:
I was trying to embed a python application called "sr1.py" into my C++ application but I'm getting this error when hovering on the #inclde <python.h>
squiggly red line:
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/Users/ImCodeName7/Documents/PlatformIO/Projects/speech_recognision/src/main.cpp).C/C++(1696) cannot open source file "python.h"C/C++(1696)
CODE:
#include <Arduino.h>
#include <python.h>
int main()
{
char filename[] = "sr1.py";
FILE* fp;
Py_Initialize();
fp = _Py_fopen(filename, "r");
PyRun_SimpleFile(fp, filename);
Py_Finalize();
return 0;
}
Please note I am still learning how to configure my environment so please bear with me. Thank you!
Edit1: The source file is mainly written in C++ (Or known as Arduino C actually!)
Assuming that this is simply a result of not including the proper path in the
c_cpp_properties.json
file.If you know the path where
python
is located all you need to do is add the following to your c_cpp_properties.json file:If you don't, then you have to do some digging. For other *NIX systems the process should be similar, for ubuntu see this post.
For example, if you use Anaconda or miniconda.
Python.h
should be located in:To find the file:
E.g.
On mac, no conda with homebrew
A little more tricky and requires a little more digging. In my case I found it located at
For windows (without any package managers) the default location is:
However, if it is not there, it should be located at one of the following locations:
%ProgramFiles%\Python X.Y
%ProgramFiles(x86)%\Python X.Y
%LocalAppData%\Programs\Python\PythonXY
%LocalAppData%\Programs\Python\PythonXY-32
%LocalAppData%\Programs\Python\PythonXY-64