2

I see many people showing how I can use the Python API in C++ however, it seems I don't have the API or reference already when I include:

#include "Python.h"

or

#include <Python.h>

I had a look at these sites and gives me everything except where I can get this reference:


I had already installed Python 2.7 and I wondered if other downloads from python.org had my answer. I installed IronPython but had no success.

Where can I get this reference?

asked Dec 7, 2012 at 16:12
3
  • IronPython is a .NET implementation of Python. You want CPython. Commented Dec 7, 2012 at 16:15
  • I have included it now I get this error: LINK : fatal error LNK1104: cannot open file 'python27_d.lib' Commented Dec 7, 2012 at 16:46
  • As the first article mentions, building in debug mode requires python27_d.lib which is not included in the normal distribution. This answer and the comments give some options for dealing with that: stackoverflow.com/questions/11311877/… Commented Dec 7, 2012 at 16:54

3 Answers 3

2

It sounds like you're unclear on how your compiler and linker works. #include is a pre-processor instruction which inserts another file into that point in the file which contains the statement. However, your compiler needs to know where to look for the file, so you need to have the folder which contains Python.h either in your IDE's list of include locations (in Visual Studio for example, this can be done either on a per-project basis, or for the whole IDE), or as an environment variable in your OS.

If the library is a header only library, then that is sufficient, as the whole of the library gets inserted into your code, which is then compiled. However, you've indicated that you're getting a LINK error, which means that although it's been able to find the declarations in Python.h, the linker doesn't know where to find the compiled definitions (which are stored in python27_d.lib). So you also need to add the location of that file to your IDE's list of library locations.

answered Dec 7, 2012 at 16:55
Sign up to request clarification or add additional context in comments.

Comments

1

You can find it \Python27\include\. So you'll need to set your include directories to have it look there.

answered Dec 7, 2012 at 16:15

Comments

0

You need to install the development package.
On Ubuntu it is python2.7-dev

answered Dec 7, 2012 at 16:52

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.