How to run matplotlib python script?

Hi,

I modified PythonDapDebugger.Wpf.MainWindow.SetupPython() method so that the sample program can recognize the installed Python. When I started the sample program and clicked the Run button, I got the following exception:

“Embedded Python distributions are not supported. Please make sure full Python 3 is installed in your system.”

The lines I modified in SetupPython() is as follows:

var pythonPath = @"C:\Python\Python38";
var pythonPrerequisitesService = new PythonPrerequisitesService(pythonPath);

What I wanted to do is to run a Python script that uses matplotlib/numpy/scipy. If the embedded Python can do that, that’ll be okay, too. I used the fully installed Python because those packages have already been installed on my machine.

Thanks.

Hi,

I tested the code you attached and it works for me on my full Python 3.8 distribution installed with a standard CPython installer to %userprofile%\AppData\Local\Programs\Python\Python38\

From the error message you are getting it looks like you have an embedded Python distribution in the specified directory, which are not supported by the DAP debugger. To verify this, we check if the Python distribution directory contains a DLLs sudirectory. The embedded distributions do not contain this subdirectory, while the full distributions do. Could you please check which kind of Python distribution you are using?

Hi Yevgeni,

There is the “DLLs” folder under C:\Python\Python38. The interpreter just works on the folder.

Thank you for the clarification.

Please modify your code like this (e.g. add the CodeEnvironment.PythonPath assignment line) and check if it works:

            var path = @"C:\Python\Python38";
            CodeEnvironment.PythonPath = path;
            var pythonPrerequisitesService = new PythonPrerequisitesService(path);

Hi Yevgeni,

I added it but then I got another exception - System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:5678.

Stack trace contained the following Alternet related ones:
at Alternet.Scripter.Debugger.Dap.Python.ScriptDebugger.d__12.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Alternet.Scripter.Debugger.Dap.ScriptDebugger.d__97.MoveNext()

Could you please send us the source code of the sample application you are having this issue with, together with a zipped Python38 directory? Then we will try to reproduce this on our end.

Where can I upload the zipped folder?

A service like Google Drive or OneDrive will do.

Here you go - Microsoft OneDrive - Access files anywhere. Create docs with free Office Online..
I put the entire Python folder, Exception text, and VS2022 About screenshot.

Thank you for uploading your Python directory contents. However, you didn’t upload a sample C# project you are experiencing this issue with, so we cannot check what is exactly happening on your side.

I modified our Python DAP debugger sample project to work with the local Python distribution you sent and the debugging works fine. You download the project by this link. It contains the Python directory you sent, so you can just open the project and run it. Please check if it works for you.

If that doesn’t help please send us your C# project you are experiencing this issue on.

Thanks for the link. I downloaded it to two PCs. Both showed exactly the same socket exception when I clicked the “Start debugging” button. Both machines are Windows 11 (21H2).

Is the string “127.0.0.1:5678” IP address and the port number of the DAP server? The exception message says that the server “actively refused the connection” on my PCs.

Is there a way to check if the server is running properly on my machines?

Hi,

Thank you for your reply. The usual culprit here is a firewall/antivirus actively blocking the communication. Can you check that by disabling both and running the sample?

I disabled both. But I continue getting the same error message. Is there a way to start the server at 127.0.0.1:5678 separately before clicking the Start Debugging button, so that I can see if it’s running by issuing “netstat -anb” command?

I contacted you by e-mail so we could work it out together.

Thanks for the link. I downloaded and ran it. It failed with the same exception with no logging in C:\Temp\debugpy-logs folder.

But, luckily, I was able to make it run by modifying the ProcessStartInfo.FileName property from just “python” to Path.Combine(pythonPath, "python.exe") in Alternet.Scripter.Debugger.Dap.Python.ScriptDebugger.ProcessStartInfo property.

I have a couple more questions:

  1. Is there a way to suppress the Pythyon command box window?
  2. How can I redirect the print() to go to the “Output” tab on the DebuggerPanelsTabControl?

Hello,

But, luckily, I was able to make it run by modifying the ProcessStartInfo.FileName property from just “python” to Path.Combine(pythonPath, "python.exe") in Alternet.Scripter.Debugger.Dap.Python.ScriptDebugger.ProcessStartInfo property.

Thank you for providing this info. This is a bug in the Python DAP debugger, we will include the fix for it in our next bugfix update.

  1. Is there a way to suppress the Pythyon command box window?
  2. How can I redirect the print() to go to the “Output” tab on the DebuggerPanelsTabControl?

I sent you a modified source file by e-mail. If that is how you would like the redirection to work, we will add a corresponding option in the debugger.

Hi Yevgeni,

That worked! Thanks for your help so far. I really appreciate it. I made a purchase requisition. I’ll close this thread. But I have another idea and will put a feature request for that.

Hi,

To let you know, we just released a 8.1.2 version of our packages, which contains the newly added Alternet.Scripter.Debugger.Dap.Python.ScriptDebugger.RedirectConsoleOutput which you can use to redirect the script output to the debugger output console. Also the packages contain the fix for the bug you reported earlier in this thread.

Thanks for the info. I appreciate it.