How can I use python in visual C++

1k Views Asked by At

I write some of my code in python. And write now I need to import it into the visual C++ 2010. I can't find any solution for this kind of problem.

The possible solution maybe convert python code into dll and import dll into visual C++ project. But I can't find any document to convert .py to .dll.

Anyone can help me?

2

There are 2 best solutions below

0
everettjf On

Boost.Python could help.

This is document. http://www.boost.org/doc/libs/1_63_0/libs/python/doc/html/index.html

Of course, you should learn the usage for boost framework and Boost.Python module.

0
Dave S On

The question is how tied are you to Visual Studio 2010?

For Visual Studio 2015 you can get the latest version of Python Tools for Visual STudio which is what I use in this environment. It is a Microsoft/Community development freeware project. They've done an excellent job with the Visual Studio Integration:

MSDN website calls it "The Python Tools for Visual Studio (PTVS), which is a free, open-source plug-in for Visual Studio that is a powerful Python development experience."

It supports CPython, IronPython, editing, browsing, IntelliSense, mixed Python/C++ debugging, remote Linux/MacOS debugging, profiling, IPython, and web development with Django and other frameworks.

So as you can see from the description it supports mixed Python/C++ projects which sounds like what you want.

You can find information and installation here: https://msdn.microsoft.com/en-us/library/dn705848.aspx

Here is some more information: https://microsoft.github.io/PTVS/