473,289 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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 "ImportError: No module named _socket".

Here is the basic test script I use:
>>>
def Process( something ):
print "\n\nStarted debugging\n=================\n"
#pydevd.settrace()
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:/Test.py\")" );
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,
Chris
Jun 27 '08 #1
4 2790
Nir
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...@gmail.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(winpdb.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 "ImportError: No module named _socket".

Here is the basic test script I use:

def Process( something ):
print "\n\nStarted debugging\n=================\n"
#pydevd.settrace()
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 withWinpdb(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:/Test.py\")" );
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 ofWinpdb.

What am I doing wrong?

Your help is highly appreciated!

Best regards,
Chris
Jun 27 '08 #2
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...@gmail.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(winpdb.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 "ImportError: No module named _socket".
Here is the basic test script I use:
def Process( something ):
print "\n\nStarted debugging\n=================\n"
#pydevd.settrace()
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 withWinpdb(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:/Test.py\")" );
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 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_SimpleString("import cgi"); -
it complained about missing _socket.

- Did PyRun_SimpleString("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\\system32\\python25.zip
C:\\Python25\\lib\\plat-win

- Added the missing path to the embedded environment:

PyRun_SimpleString("import sys");
PyRun_SimpleString("import os");

PyRun_SimpleString("sys.path.append(\"C:\\WINDOWS\ \system32\
\python25.zip\")");
PyRun_SimpleString("sys.path.append(\"C:\\Python25 \\lib\\plat-win
\")");

PyRun_SimpleString("print sys.path");

PyRun_SimpleString("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\Lib\cgi.py", line 40, in <module>
import urllib
File "c:\Python25\lib\urllib.py", line 26, in <module>
import socket
File "c:\Python25\lib\socket.py", line 45, in <module>
import _socket
ImportError: No module named _socket

Chris

Jun 27 '08 #3
On Jun 6, 11:25 am, Chris8B...@gmail.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...@gmail.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(winpdb.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 "ImportError: No module named _socket".
Here is the basic test script I use:
def Process( something ):
print "\n\nStarted debugging\n=================\n"
#pydevd.settrace()
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 withWinpdb(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:/Test.py\")" );
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 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_SimpleString("import cgi"); -
it complained about missing _socket.

- Did PyRun_SimpleString("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\\system32\\python25.zip
C:\\Python25\\lib\\plat-win

- Added the missing path to the embedded environment:

PyRun_SimpleString("import sys");
PyRun_SimpleString("import os");

PyRun_SimpleString("sys.path.append(\"C:\\WINDOWS\ \system32\
\python25.zip\")");
PyRun_SimpleString("sys.path.append(\"C:\\Python25 \\lib\\plat-win
\")");

PyRun_SimpleString("print sys.path");

PyRun_SimpleString("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\Lib\cgi.py", line 40, in <module>
import urllib
File "c:\Python25\lib\urllib.py", line 26, in <module>
import socket
File "c:\Python25\lib\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
Jun 27 '08 #4
Nir
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...@gmail.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...@gmail.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(winpdb.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 "ImportError: No module named _socket".
Here is the basic test script I use:
def Process( something ):
print "\n\nStarted debugging\n=================\n"
#pydevd.settrace()
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 withWinpdb(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:/Test.py\")" );
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 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_SimpleString("import cgi"); -
it complained about missing _socket.

- Did PyRun_SimpleString("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\\system32\\python25.zip
C:\\Python25\\lib\\plat-win

- Added the missing path to the embedded environment:

PyRun_SimpleString("import sys");
PyRun_SimpleString("import os");

PyRun_SimpleString("sys.path.append(\"C:\\WINDOWS\ \system32\
\python25.zip\")");
PyRun_SimpleString("sys.path.append(\"C:\\Python25 \\lib\\plat-win
\")");

PyRun_SimpleString("print sys.path");

PyRun_SimpleString("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\Lib\cgi.py", line 40, in <module>
import urllib
File "c:\Python25\lib\urllib.py", line 26, in <module>
import socket
File "c:\Python25\lib\socket.py", line 45, in <module>
import _socket
ImportError: No module named _socket

Chris
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Miki Tebeka | last post by:
Hello All, I have a funny problem: An embedded python application is working fine on a "clean" computer. When it runs on a computer with python installed (the very same computer used to...
1
by: amit | last post by:
Hello, I am embedding a python script in a C++ application. The script can be called simultaneously from multiple threads. What is the correct way to implement this situation: 1) Have...
2
by: fotis | last post by:
hello there! I am playing with embedded python these days. I wrote sth like this: ------------------------------ Code ------------------------------- #include <Python.h> #include <iostream>...
5
by: wahn | last post by:
Hi, Here is a problem I came across and need some help with. I developed a little Python script with some classes which runs standalone and communicates with a database via sockets. So far...
3
by: Torsten Bronger | last post by:
Hallöchen! I'd like to script C++ funtions by an embedded Python interpreter. So far, my C++ main() function contains: Py_Initialize(); Py_InitModule("pp3", PythonMethods);...
7
by: wardm | last post by:
I have created a Dict object in a C++ App that calls (embedded) Python functions. The Dict is to be used to pass variable data between the C++ App and the python functions. However I cannot get...
0
by: vishnu | last post by:
Hello All, I have embedded python 2.5 in to my C application. As we need the python scripts to run in multi threaded environment I have used Py_NewInterpreter() and Py_EndInterpreter each time I...
0
by: PlayDough | last post by:
I've embedded Python in an extension for a program we are using here at work. And I'm a bit stumped as to why I am getting an AttributeError only in the embedded Python. First, a bit of what I...
0
by: Matthew Severin | last post by:
Having some trouble getting rpdb2 and winpdb running properly with Python embedded in a C++ project. Our implementation has a number of C++ classes associated with Python classes. I am able...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.