Looks like you haven't properly installed the header files and static libraries for python dev. Use your package manager to install them system-wide.
For apt (Ubuntu, Debian...):
sudo apt install python-dev # for python2.x installs
sudo apt install python3-dev # for python3.x installs
For yum (CentOS, RHEL...):
sudo yum install python-devel # for python2.x installs
sudo yum install python3-devel # for python3.x installs
For dnf (Fedora...):
sudo dnf install python2-devel # for python2.x installs
sudo dnf install python3-devel # for python3.x installs
For zypper (openSUSE...):
sudo zypper in python-devel # for python2.x installs
sudo zypper in python3-devel # for python3.x installs
For apk (Alpine...):
# 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
For apt-cyg (Cygwin...):
apt-cyg install python-devel # for python2.x installs
apt-cyg install python3-devel # for python3.x installs
Important Note: python3-dev/devel does not automatically cover all minor versions of python3.
E.g If you are using python 3.11 you may need to install python3.11-dev / python3.11-devel.
Looks like you haven't properly installed the header files and static libraries for python dev. Use your package manager to install them system-wide.
For apt (Ubuntu, Debian...):
sudo apt install python-dev # for python2.x installs
sudo apt install python3-dev # for python3.x installs
For yum (CentOS, RHEL...):
sudo yum install python-devel # for python2.x installs
sudo yum install python3-devel # for python3.x installs
For dnf (Fedora...):
sudo dnf install python2-devel # for python2.x installs
sudo dnf install python3-devel # for python3.x installs
For zypper (openSUSE...):
sudo zypper in python-devel # for python2.x installs
sudo zypper in python3-devel # for python3.x installs
For apk (Alpine...):
# 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
For apt-cyg (Cygwin...):
apt-cyg install python-devel # for python2.x installs
apt-cyg install python3-devel # for python3.x installs
Important Note: python3-dev/devel does not automatically cover all minor versions of python3.
E.g If you are using python 3.11 you may need to install python3.11-dev / python3.11-devel.
On Ubuntu, I was running Python 3 and I had to install
sudo apt-get install python3-dev
If you want to use a version of Python that is not linked to python3, install the associated python3.x-dev package. For example:
sudo apt-get install python3.5-dev
I have the latest python3-dev python-dev installed, but the header isn't found. I have read that Python.h is no longer inside python-dev but don't know where, how to get it? I have also tried sudo apt install python-dev-is-python3 but it still doesn't work.
I'm trying to write a Python library in C. My code uses #include <Python.h> but VSCode says:
"include errors detected. Please update your includePath. Squiggles are disabled for this translation unit."
What does this mean and how do I go about fixing this? (Sorry if it's obvious, I'm not new to Python but very new to C)
You need to qualify your include
#include <python2.7/Python.h>
Or tell gcc where to find Python.h with the
gcc -I /usr/include/python2.7/ program.c
You need to provide GCC with the include path for the Python.h header. This can be done with the -I flag:
gcc -c -I/usr/include/python2.7 sourcefile.c
However, there is a better way: use pkg-config :
pkg-config --cflags python
This will output the flags that need to be passed to GCC in order to compile applications that use the Python headers and libraries.
When linking, use the output of this command to include the appropriate libraries:
pkg-config --libs python
You could even combine both steps with:
gcc `pkg-config --cflags --libs python` sourcefile.c
Try installing the package libpython3.8-dev, that should put the Python.h file into /usr/include/python3.8/Python.h
Use apt-file search Python.h to find the packages that contain it. After installing apt-file, you will need to run apt-file update to let it update its database.
You can try the following:
sudo updatedb
locate Python.h
Output:
/usr/include/python2.7/Python.h
/usr/include/python3.5m/Python.h
Then set
export CPATH=/usr/include/python3.5m:$CPATH
export LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH
For Python 3:
sudo apt-get install python-dev python3-dev
You can also install it for specific versions of Python (if available for your version of Ubuntu, or from a PPA):
sudo apt-get install python3.4-dev
sudo apt-get install python3.5-dev
The python3-dev package depends on a python3.x-dev package, (where 3.x is the system version of Python) and on the libpython3-dev package, which in turn depends on a corresponding libpython3.x-dev package.
After looking at https://github.com/hrldcpr/hungarian/blob/master/hungarian.cpp, it seems that you need both:
#include "Python.h"
#include "numpy/arrayobject.h"
So install the following packages:
sudo apt-get install libpython2.7-dev python-numpy
To identify the missing packages (the ones providing the headers), look at packages.ubuntu.com.