3

I'm kinda new to C, and I can't seem to do what I want. I need to make some Python bindings for C functions, and I think I can figure this out. But there's one little line that WILL NOT WORK.

#include <Python.h>

I get this:

fatal error #1035: Can't find include file <Python.h>.

I've tried everything. I just stuck Python.h in the same folder as my project first. Then I put the file name in Library and Object files under linker. Then I did the same with python31.lib, then I put the directory python31.lib is in in my PATH variable. Nothing will let me get past this line. I see a lot of solutions on the net for Linux, but none for Windows. Please help!

GreenAsJade
  • 14,459
  • 11
  • 63
  • 98
Void Star
  • 2,401
  • 4
  • 32
  • 57
  • `#include "Python.h"` will find it if it's in the same directory. Linking is a different issue. Check your include path. What command line are you passing to GCC? – nmichaels Aug 19 '11 at 18:03
  • @nmichaels Looks like he's building in Windows, so GCC is irrelephant. – Santa Aug 19 '11 at 18:09
  • If all you need to do is generate Python bindings for C functions, use https://code.google.com/p/ctypesgen/, it can probably do it automatically. – agf Aug 19 '11 at 18:12
  • 1
    Oh! Thanks man! I thought I was screwed then I read that it should find the file if it's in the same directory as my source (it didn't). But I thought I'd follow through and check my include path (which I didn't even know existed). So I added the Python include path to the list of include paths, and did the same with Python libraries (to the libraries paths), and it compiled without any issues. Why have I not found stack overflow earlier??? You guys are the best! – Void Star Aug 19 '11 at 18:14
  • How do I mark this question as answered? – Void Star Aug 19 '11 at 18:15
  • 6
    @Santa Thanks for the irrelephant. Next year can I get an irrrhinoceros? – nmichaels Aug 19 '11 at 18:26

2 Answers2

4

Whoops, answered in a comment. Here's a more answerly answer.

Make sure you put Python.h in your include path and the library in your library path.

nmichaels
  • 49,466
  • 12
  • 107
  • 135
3

Try:

sudo apt-get install python2.6-dev

if your Python version is python2.6

Rafał Rawicki
  • 22,324
  • 5
  • 59
  • 79
andy
  • 89
  • 4
  • 1
    It probably depends on what is being compiled, but plain `sudo apt-get install python-dev` worked well for me. – Joel Purra Oct 26 '12 at 16:42