Cannot use Winpdb (or PyDev) to trace embedded Python script in MSVC++ application - ImportError: No module named _socket

Chris8Boyd at Chris8Boyd at
Thu Jun 5 17:52:57 EDT 2008

I am embedding Python in a MSVC++ (2005) application. The application
creates some environment and then launches a Python script that will
call some functions exported from the MSVC++ application.

I want to be able to debug the Python script by using a debug server,
like Winpdb (

I use ActivePython, Microsoft Visual Studio 2005, and Winpdb

When I launch a script like "e:>python" everything is O'K and
I can use Winpdb to trace/debug.

When I run the same script from the MSVC++ application, there is
always a complain "ImportError: No module named _socket".

Here is the basic test script I use:

def Process( something ):
    print "\n\nStarted debugging\n=================\n"
    import rpdb2; rpdb2.start_embedded_debugger("1")
    print "\n\nStopped debugging\n=================\n"

if __name__ == '__main__':
    Process( "test" )

In the MSVC++ application I tried many approaches, as suggested by
many people, and all of them work to launch the script, but none of
them works with Winpdb (or PyDev for Eclipse - same problem). Just for
completeness - here is one:

  PyRun_SimpleString("import sys");
  PyRun_SimpleString("import os");
  PyRun_SimpleString( "fullpath = os.path.abspath(\"E:/\")" );
  PyRun_SimpleString( "g = globals().copy()" );
  PyRun_SimpleString( "g['__file__'] = fullpath");
  PyRun_SimpleString( "execfile(fullpath, g) ");

If I use pdb (import pdb + pdb.runcall(something) ) everything works
fine, but I need the performance and convinience of Winpdb.

What am I doing wrong?

Your help is highly appreciated!

Best regards,

More information about the Python-list mailing list