Debug vs Release mode to C module: How can I use python_d.exe in PTVS?

Jun 4, 2014 at 6:42 PM

I'm using PTVS 2.1, MSVC 2013 and Python 3.4.

I've made a Python project with a C module. In RELEASE mode it is outputtting mymodule.pyd, in DEBUG, mymodule_d.pyd.

So, in order to get some debug libraries, I've built the Python-3.4.0 from source and I've got python_d.exe.

What can I do to run my project in DEBUG mode? Should I create a new environment to python_d.exe?

Can I move this python_d.exe to the Python's path (C:\Python34) in order to use the same packages on site-packages?

Thank you in advance.

Jun 4, 2014 at 7:00 PM
The easiest approach is probably to set the Interpreter Path property in your project (Project Properties, Debug tab) to the full path to python_d.exe. Assuming you have an install of Python 3.4 already, this will save you from having to reanalyze all of the standard library.

Moving the file into the Python install should work for picking up the same site-packages. There are other ways to do this, but I'm not sure that they are easier to achieve than simply moving the file (note that you'll need to copy the *_d.pyd files as well).

Another alternative is to use the following code when including python.h in your module:
#ifdef _DEBUG
#undef _DEBUG
#include <Python.h>
#define _DEBUG
It's a little complex, but it should mean that you always build your extension against the release version of Python, even when your extension is built in debug mode.
Marked as answer by kochdaniel7 on 6/4/2014 at 11:56 AM
Jun 4, 2014 at 7:19 PM

Changing the Interpreter Path property in the project doesn't fit the issue. The python-d.exe won't use the default site-packages (Should I create some sort of environment variable)?

Copying the content of PCBuild\ to C:\Python34 is OK. I've created a new environment and I have just have to switch it when I want to run my project with python_d.exe or python.exe.

The last tip will work only if my project outputs the pyd with the same name in the same place (like PCBuild folder, not in Debug and Release), because python.exe won't import a file named mymodule_d.pyd.

Thank you @Zooba!

Jun 4, 2014 at 7:22 PM
The only problem here is that I have to remember to change the environment when I swap between Debug and Release.
Jun 4, 2014 at 7:28 PM
We really need to make all the interpreter settings & search path stuff to be configuration-specific properties. There's a work item to track the work that needs to be done there: