Cannot use Winpdb (or PyDev) to trace embedded Python script in

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris8Boyd@gmail.com

    Cannot use Winpdb (or PyDev) to trace embedded Python script in

    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 (winpdb.org).

    I use ActivePython 2.5.2.2, Microsoft Visual Studio 2005, and Winpdb
    1.3.8.

    When I launch a script like "e:>python test.py" 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 "ImportErro r: No module named _socket".

    Here is the basic test script I use:
    >>>
    def Process( something ):
    print "\n\nStarte d debugging\n==== =============\n "
    #pydevd.settrac e()
    import rpdb2; rpdb2.start_emb edded_debugger( "1")
    print "\n\nStoppe d 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_SimpleStr ing("import sys");
    PyRun_SimpleStr ing("import os");
    PyRun_SimpleStr ing( "fullpath = os.path.abspath (\"E:/Test.py\")" );
    PyRun_SimpleStr ing( "g = globals().copy( )" );
    PyRun_SimpleStr ing( "g['__file__'] = fullpath");
    PyRun_SimpleStr ing( "execfile(fullp ath, g) ");
    <<<

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

    What am I doing wrong?

    Your help is highly appreciated!

    Best regards,
    Chris
  • Nir

    #2
    Re: Cannot use Winpdb (or PyDev) to trace embedded Python script in

    You seem to be having a problem with the import path of the embedded
    interpreter. I suppose the embedded interpreter includes some modules
    in a particular folder and _socket is not one of them. For the sake of
    debugging try adding the c:\python25\lib path to the sys.path variable
    of the interpreter before attempting to import rpdb2.

    Does this work?

    Nir


    On Jun 5, 2:52 pm, Chris8B...@gmai l.com wrote:
    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,
    likeWinpdb(winp db.org).
    >
    I use ActivePython 2.5.2.2, Microsoft Visual Studio 2005, andWinpdb
    1.3.8.
    >
    When I launch a script like "e:>python test.py" everything is O'K and
    I can useWinpdbto trace/debug.
    >
    When I run the same script from the MSVC++ application, there is
    always a complain "ImportErro r: No module named _socket".
    >
    Here is the basic test script I use:
    >
    >
    >
    def Process( something ):
    print "\n\nStarte d debugging\n==== =============\n "
    #pydevd.settrac e()
    import rpdb2; rpdb2.start_emb edded_debugger( "1")
    print "\n\nStoppe d 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 withWinpdb(or PyDev for Eclipse - same problem). Just for
    completeness - here is one:
    >
    >
    >
    PyRun_SimpleStr ing("import sys");
    PyRun_SimpleStr ing("import os");
    PyRun_SimpleStr ing( "fullpath = os.path.abspath (\"E:/Test.py\")" );
    PyRun_SimpleStr ing( "g = globals().copy( )" );
    PyRun_SimpleStr ing( "g['__file__'] = fullpath");
    PyRun_SimpleStr ing( "execfile(fullp ath, g) ");
    <<<
    >
    If I use pdb (import pdb + pdb.runcall(som ething) ) everything works
    fine, but I need the performance and convinience ofWinpdb.
    >
    What am I doing wrong?
    >
    Your help is highly appreciated!
    >
    Best regards,
    Chris

    Comment

    • Chris8Boyd@gmail.com

      #3
      Re: Cannot use Winpdb (or PyDev) to trace embedded Python script in

      On Jun 6, 1:13 am, Nir <nir1...@gmail. comwrote:
      You seem to be having a problem with the import path of the embedded
      interpreter. I suppose the embedded interpreter includes some modules
      in a particular folder and _socket is not one of them. For the sake of
      debugging try adding the c:\python25\lib path to the sys.path variable
      of the interpreter before attempting to import rpdb2.
      >
      Does this work?
      >
      Nir
      >
      On Jun 5, 2:52 pm, Chris8B...@gmai l.com wrote:
      >
      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,
      likeWinpdb(winp db.org).
      >
      I use ActivePython 2.5.2.2, Microsoft Visual Studio 2005, andWinpdb
      1.3.8.
      >
      When I launch a script like "e:>python test.py" everything is O'K and
      I can useWinpdbto trace/debug.
      >
      When I run the same script from the MSVC++ application, there is
      always a complain "ImportErro r: No module named _socket".
      >
      Here is the basic test script I use:
      >
      def Process( something ):
      print "\n\nStarte d debugging\n==== =============\n "
      #pydevd.settrac e()
      import rpdb2; rpdb2.start_emb edded_debugger( "1")
      print "\n\nStoppe d 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 withWinpdb(or PyDev for Eclipse - same problem). Just for
      completeness - here is one:
      >
      PyRun_SimpleStr ing("import sys");
      PyRun_SimpleStr ing("import os");
      PyRun_SimpleStr ing( "fullpath = os.path.abspath (\"E:/Test.py\")" );
      PyRun_SimpleStr ing( "g = globals().copy( )" );
      PyRun_SimpleStr ing( "g['__file__'] = fullpath");
      PyRun_SimpleStr ing( "execfile(fullp ath, g) ");
      <<<
      >
      If I use pdb (import pdb + pdb.runcall(som ething) ) everything works
      fine, but I need the performance and convinience ofWinpdb.
      >
      What am I doing wrong?
      >
      Your help is highly appreciated!
      >
      Best regards,
      Chris
      Nir,
      Does this work?
      Unfortunately, not.

      I did some experiments to check the sys.path hypothesis:

      - In my MSVC++ application I did PyRun_SimpleStr ing("import cgi"); -
      it complained about missing _socket.

      - Did PyRun_SimpleStr ing("print sys.path") to get the sys.path as seen
      from within the application environment (that does not find _socket)

      - Did the same in "test.py" and ran ...>Python test.py to get the
      sys.path for the environment that _does_ find _socket

      - Compared the two - the working environment had two more paths:

      C:\\WINDOWS\\sy stem32\\python2 5.zip
      C:\\Python25\\l ib\\plat-win

      - Added the missing path to the embedded environment:

      PyRun_SimpleStr ing("import sys");
      PyRun_SimpleStr ing("import os");

      PyRun_SimpleStr ing("sys.path.a ppend(\"C:\\WIN DOWS\\system32\
      \python25.zip\" )");
      PyRun_SimpleStr ing("sys.path.a ppend(\"C:\\Pyt hon25\\lib\\pla t-win
      \")");

      PyRun_SimpleStr ing("print sys.path");

      PyRun_SimpleStr ing("import cgi");

      Not all paths that are in the working environment are present in the
      embedded environment, but still there is a problem:

      Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Python25\Li b\cgi.py", line 40, in <module>
      import urllib
      File "c:\Python25\li b\urllib.py", line 26, in <module>
      import socket
      File "c:\Python25\li b\socket.py", line 45, in <module>
      import _socket
      ImportError: No module named _socket

      Chris



      Comment

      • Chris8Boyd@gmail.com

        #4
        Re: Cannot use Winpdb (or PyDev) to trace embedded Python script in

        On Jun 6, 11:25 am, Chris8B...@gmai l.com wrote:
        On Jun 6, 1:13 am, Nir <nir1...@gmail. comwrote:
        >
        >
        >
        You seem to be having a problem with the import path of the embedded
        interpreter. I suppose the embedded interpreter includes some modules
        in a particular folder and _socket is not one of them. For the sake of
        debugging try adding the c:\python25\lib path to the sys.path variable
        of the interpreter before attempting to import rpdb2.
        >
        Does this work?
        >
        Nir
        >
        On Jun 5, 2:52 pm, Chris8B...@gmai l.com wrote:
        >
        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,
        likeWinpdb(winp db.org).
        >
        I use ActivePython 2.5.2.2, Microsoft Visual Studio 2005, andWinpdb
        1.3.8.
        >
        When I launch a script like "e:>python test.py" everything is O'K and
        I can useWinpdbto trace/debug.
        >
        When I run the same script from the MSVC++ application, there is
        always a complain "ImportErro r: No module named _socket".
        >
        Here is the basic test script I use:
        >
        def Process( something ):
        print "\n\nStarte d debugging\n==== =============\n "
        #pydevd.settrac e()
        import rpdb2; rpdb2.start_emb edded_debugger( "1")
        print "\n\nStoppe d 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 withWinpdb(or PyDev for Eclipse - same problem). Just for
        completeness - here is one:
        >
        PyRun_SimpleStr ing("import sys");
        PyRun_SimpleStr ing("import os");
        PyRun_SimpleStr ing( "fullpath = os.path.abspath (\"E:/Test.py\")" );
        PyRun_SimpleStr ing( "g = globals().copy( )" );
        PyRun_SimpleStr ing( "g['__file__'] = fullpath");
        PyRun_SimpleStr ing( "execfile(fullp ath, g) ");
        <<<
        >
        If I use pdb (import pdb + pdb.runcall(som ething) ) everything works
        fine, but I need the performance and convinience ofWinpdb.
        >
        What am I doing wrong?
        >
        Your help is highly appreciated!
        >
        Best regards,
        Chris
        >
        Nir,
        >
        Does this work?
        >
        Unfortunately, not.
        >
        I did some experiments to check the sys.path hypothesis:
        >
        - In my MSVC++ application I did PyRun_SimpleStr ing("import cgi"); -
        it complained about missing _socket.
        >
        - Did PyRun_SimpleStr ing("print sys.path") to get the sys.path as seen
        from within the application environment (that does not find _socket)
        >
        - Did the same in "test.py" and ran ...>Python test.py to get the
        sys.path for the environment that _does_ find _socket
        >
        - Compared the two - the working environment had two more paths:
        >
        C:\\WINDOWS\\sy stem32\\python2 5.zip
        C:\\Python25\\l ib\\plat-win
        >
        - Added the missing path to the embedded environment:
        >
        PyRun_SimpleStr ing("import sys");
        PyRun_SimpleStr ing("import os");
        >
        PyRun_SimpleStr ing("sys.path.a ppend(\"C:\\WIN DOWS\\system32\
        \python25.zip\" )");
        PyRun_SimpleStr ing("sys.path.a ppend(\"C:\\Pyt hon25\\lib\\pla t-win
        \")");
        >
        PyRun_SimpleStr ing("print sys.path");
        >
        PyRun_SimpleStr ing("import cgi");
        >
        Not all paths that are in the working environment are present in the
        embedded environment, but still there is a problem:
        >
        Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "C:\Python25\Li b\cgi.py", line 40, in <module>
        import urllib
        File "c:\Python25\li b\urllib.py", line 26, in <module>
        import socket
        File "c:\Python25\li b\socket.py", line 45, in <module>
        import _socket
        ImportError: No module named _socket
        >
        Chris
        There is a typo:

        "Not all paths that are in the working environment are present in the
        embedded environment, but still there is a problem:"

        should read

        "Now all paths...."

        Sorry!

        Chirs

        Comment

        • Nir

          #5
          Re: Cannot use Winpdb (or PyDev) to trace embedded Python script in

          Can you check another hypothesis?

          I currently do not have a Python installation to verify this but if my
          memory does not fail me there is a DLL library somewhere under c:
          \python25 and _socket might be there as well. Copy any DLLs you find
          there to the same folder as your embedded interpreter DLL and see if
          the problem is resolved.

          Nir


          On Jun 6, 11:25 am, Chris8B...@gmai l.com wrote:
          On Jun 6, 1:13 am, Nir <nir1...@gmail. comwrote:
          >
          >
          >
          You seem to be having a problem with the import path of the embedded
          interpreter. I suppose the embedded interpreter includes some modules
          in a particular folder and _socket is not one of them. For the sake of
          debugging try adding the c:\python25\lib path to the sys.path variable
          of the interpreter before attempting to import rpdb2.
          >
          Does this work?
          >
          Nir
          >
          On Jun 5, 2:52 pm, Chris8B...@gmai l.com wrote:
          >
          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,
          likeWinpdb(winp db.org).
          >
          I use ActivePython 2.5.2.2, Microsoft Visual Studio 2005, andWinpdb
          1.3.8.
          >
          When I launch a script like "e:>python test.py" everything is O'K and
          I can useWinpdbto trace/debug.
          >
          When I run the same script from the MSVC++ application, there is
          always a complain "ImportErro r: No module named _socket".
          >
          Here is the basic test script I use:
          >
          def Process( something ):
          print "\n\nStarte d debugging\n==== =============\n "
          #pydevd.settrac e()
          import rpdb2; rpdb2.start_emb edded_debugger( "1")
          print "\n\nStoppe d 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 withWinpdb(or PyDev for Eclipse - same problem). Just for
          completeness - here is one:
          >
          PyRun_SimpleStr ing("import sys");
          PyRun_SimpleStr ing("import os");
          PyRun_SimpleStr ing( "fullpath = os.path.abspath (\"E:/Test.py\")" );
          PyRun_SimpleStr ing( "g = globals().copy( )" );
          PyRun_SimpleStr ing( "g['__file__'] = fullpath");
          PyRun_SimpleStr ing( "execfile(fullp ath, g) ");
          <<<
          >
          If I use pdb (import pdb + pdb.runcall(som ething) ) everything works
          fine, but I need the performance and convinience ofWinpdb.
          >
          What am I doing wrong?
          >
          Your help is highly appreciated!
          >
          Best regards,
          Chris
          >
          Nir,
          >
          Does this work?
          >
          Unfortunately, not.
          >
          I did some experiments to check the sys.path hypothesis:
          >
          - In my MSVC++ application I did PyRun_SimpleStr ing("import cgi"); -
          it complained about missing _socket.
          >
          - Did PyRun_SimpleStr ing("print sys.path") to get the sys.path as seen
          from within the application environment (that does not find _socket)
          >
          - Did the same in "test.py" and ran ...>Python test.py to get the
          sys.path for the environment that _does_ find _socket
          >
          - Compared the two - the working environment had two more paths:
          >
          C:\\WINDOWS\\sy stem32\\python2 5.zip
          C:\\Python25\\l ib\\plat-win
          >
          - Added the missing path to the embedded environment:
          >
          PyRun_SimpleStr ing("import sys");
          PyRun_SimpleStr ing("import os");
          >
          PyRun_SimpleStr ing("sys.path.a ppend(\"C:\\WIN DOWS\\system32\
          \python25.zip\" )");
          PyRun_SimpleStr ing("sys.path.a ppend(\"C:\\Pyt hon25\\lib\\pla t-win
          \")");
          >
          PyRun_SimpleStr ing("print sys.path");
          >
          PyRun_SimpleStr ing("import cgi");
          >
          Not all paths that are in the working environment are present in the
          embedded environment, but still there is a problem:
          >
          Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "C:\Python25\Li b\cgi.py", line 40, in <module>
          import urllib
          File "c:\Python25\li b\urllib.py", line 26, in <module>
          import socket
          File "c:\Python25\li b\socket.py", line 45, in <module>
          import _socket
          ImportError: No module named _socket
          >
          Chris

          Comment

          Working...