2

Want to extend my c++ with some python.

file im building:

#include <Python.h>

error:

[DIR]:1:20: fatal error: Python.h: No such file or directory
#include <Python.h>

I am using sublime text 2 to build my code

sudo apt-get install python-dev 

locate Python.h
/usr/include/python2.7/Python.h

^python dev is up to date

found a few google links talking about including a build path or something, but this is not my strong side

-I/usr/include/python2.7/

tried adding this to the build command in the C++.sublime-text file under packages, but just broke the build system instead. Help, im a clueless little man

  • +1 for calling yourself a clueless little man – wim Aug 21 '14 at 09:53
  • 1
    what is the output of this command on your system: `sudo updatedb && locate Python.h` – wim Aug 21 '14 at 09:55
  • `~/Downloads/Python-2.7.5/Include/Python.h` `/usr/include/python2.7/Python.h` `/usr/local/include/python2.7/Python.h` thanks for your time – user3797085 Aug 21 '14 at 10:04
  • Have you looked at the similar questions? http://stackoverflow.com/questions/11041299/python-h-no-such-file-or-directory?rq=1 – RvdK Aug 21 '14 at 11:36

1 Answers1

1

In Sublime-Text/Packages/C++ (which you can find by going preferences->browse packages->C++) edit the file called C++.sublime-build. In the 'cmd' line:

UBUNTU

"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"]

add '-I/usr/include/python2.7 -lpython2.7' as follows: (/usr/include/python2.7 is the Python.h directory)

"cmd": ["g++", "-I/usr/include/python2.7", "${file}", "-lpython2.7", "-o", "${file_path}/${file_base_name}"]

Windows

"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"]

add '-I/Python27/include' as follows: (/Python27/include is the Python.h directory)

"cmd": ["g++", "${file}", "-I/Python27/include", "-L/Python27/libs", "-lpython27", "-o", "${file_path}/${file_base_name}"]

save and you are ready to 'supercharge' your code ;)

note: i am terrible with stuff like building code so this may very well not be the most elegant way of fixing the issue