Extending Python with Visual C++ and PTVS

Last month there was a chance I gave a talk explaining how to start the PTVS(Python Tools for Visual Studio) through the MS virtual academy. The talk was live recorded and currently is being shared following URL:

http://www.microsoftvirtualacademy.com/training-courses/-ptvs-python-tools-for-visual-studio-python

It’s Korean though. Throughout the demo, except the very basic examples I also included demos showing how to build a Python extension with C++ which is integrated greatly with Visual Studio C++ compiler and the PTVS, and how to debug cross platform python modules running on Raspberry Pi.

Although the C++ python extension example I wrote was super simple and copy&pasted almost from python.org example, I uploaded mine here including C++ and python sample sources because it wasn’t easy to find as complete visual studio solution form.

GitHub repo URL: https://github.com/heejune/demo-python-PyCExtDemo1

Also if you want to start building a C++ python extension with Visual Studio and PTVS please refer to following steps:

1. Specify the include directory contains python headers.

python_header

2. Add python27.lib or appropriate version corresponds to.

python_lib

3. Add libs directory into additional lib path.

python_lib_dirpath

4. Lastly, don’t forget enabling ‘Mixed mode debugging’ and matching python environment’s architecture version with python extension architecture (as follows)

confirm_arch

Thanks,

Heejune

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s