Ekrem Dinçel
Ekrem Dinçel

Reputation: 1141

How can I use Python.h file to make python C extensions

I want to make c extension for python. I know basics of C, and i want to make extensions because of better performance. I dont know Visual Studio and C very well. So please be considerate.

I searched to much but i didnt find any working solution. When i am trying to #include <Python.h> file, it is saying it cant find it. What should i do?

Upvotes: 0

Views: 230

Answers (1)

ivan_pozdeev
ivan_pozdeev

Reputation: 36106

MS has a document dedicated to your exact case, with step-by-step instructions: Write C++ extensions for Python - Visual Studio | Microsoft Docs

In brief, you

  • Create a C++ DLL project
  • link it against pythonXY.dll as per Link against a 3rd-party library with Visual Studio
  • specify some Python-specific settings:
  • Create a Python project and support .py files in it, e.g. setup.py
  • Reference the C++ project from the Python project. That will build the .pyd before running the Python project and make it available for Python code in it.

Note that there's no further integration with distutils, pytest, tox and whatnot.

Upvotes: 1

Related Questions