# How to run matplotlib python script?

**URL:** <https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315>\
**Category:** AlterNET Studio Support\
**Tags:** wpf, python\
**Created:** [July 15, 2022, 7:13pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315 "2022-07-15T19:13:02Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tetsu](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@Tetsu](https://forum.alternetsoft.com/u/Tetsu)\
**Post date:** [July 15, 2022, 7:13pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/1 "2022-07-15T19:13:02Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![yevgeni.zolotko](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/yevgeni.zolotko/32/25_2.png) [@yevgeni.zolotko](https://forum.alternetsoft.com/u/yevgeni.zolotko)\
**Post date:** [July 20, 2022, 1:24pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/2 "2022-07-20T13:24:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Tetsu](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@Tetsu](https://forum.alternetsoft.com/u/Tetsu)\
**Post date:** [July 21, 2022, 1:53pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/3 "2022-07-21T13:53:58Z")

</div>

Hi Yevgeni,

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

---

<div class="post-metadata">

**Author:** ![yevgeni.zolotko](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/yevgeni.zolotko/32/25_2.png) [@yevgeni.zolotko](https://forum.alternetsoft.com/u/yevgeni.zolotko)\
**Post date:** [July 22, 2022, 7:54am UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/4 "2022-07-22T07:54:40Z")

</div>

Thank you for the clarification.

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

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

```

---

<div class="post-metadata">

**Author:** ![Tetsu](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@Tetsu](https://forum.alternetsoft.com/u/Tetsu)\
**Post date:** [July 22, 2022, 5:02pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/5 "2022-07-22T17:02:43Z")

</div>

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()

---

<div class="post-metadata">

**Author:** ![yevgeni.zolotko](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/yevgeni.zolotko/32/25_2.png) [@yevgeni.zolotko](https://forum.alternetsoft.com/u/yevgeni.zolotko)\
**Post date:** [July 24, 2022, 5:54pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/6 "2022-07-24T17:54:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tetsu](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@Tetsu](https://forum.alternetsoft.com/u/Tetsu)\
**Post date:** [July 24, 2022, 6:30pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/7 "2022-07-24T18:30:42Z")

</div>

Where can I upload the zipped folder?

---

<div class="post-metadata">

**Author:** ![yevgeni.zolotko](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/yevgeni.zolotko/32/25_2.png) [@yevgeni.zolotko](https://forum.alternetsoft.com/u/yevgeni.zolotko)\
**Post date:** [July 25, 2022, 12:11pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/8 "2022-07-25T12:11:19Z")

</div>

A service like Google Drive or OneDrive will do.

---

<div class="post-metadata">

**Author:** ![Tetsu](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@Tetsu](https://forum.alternetsoft.com/u/Tetsu)\
**Post date:** [July 25, 2022, 5:52pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/9 "2022-07-25T17:52:10Z")

</div>

Here you go - [Microsoft OneDrive - Access files anywhere. Create docs with free Office Online.](https://1drv.ms/u/s!AgGlODg7k44shjAOWJS7B24RXPCv).  
I put the entire Python folder, Exception text, and VS2022 About screenshot.

---

<div class="post-metadata">

**Author:** ![yevgeni.zolotko](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/yevgeni.zolotko/32/25_2.png) [@yevgeni.zolotko](https://forum.alternetsoft.com/u/yevgeni.zolotko)\
**Post date:** [July 26, 2022, 8:23am UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/10 "2022-07-26T08:23:18Z")

</div>

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](https://alternetsoftware.blob.core.windows.net/forum/PythonDapDebugger.zip). 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.

---

<div class="post-metadata">

**Author:** ![Tetsu](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@Tetsu](https://forum.alternetsoft.com/u/Tetsu)\
**Post date:** [July 26, 2022, 12:21pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/11 "2022-07-26T12:21:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![yevgeni.zolotko](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/yevgeni.zolotko/32/25_2.png) [@yevgeni.zolotko](https://forum.alternetsoft.com/u/yevgeni.zolotko)\
**Post date:** [July 27, 2022, 8:03am UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/12 "2022-07-27T08:03:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Tetsu](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@Tetsu](https://forum.alternetsoft.com/u/Tetsu)\
**Post date:** [July 27, 2022, 3:57pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/13 "2022-07-27T15:57:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![yevgeni.zolotko](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/yevgeni.zolotko/32/25_2.png) [@yevgeni.zolotko](https://forum.alternetsoft.com/u/yevgeni.zolotko)\
**Post date:** [July 28, 2022, 8:26am UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/14 "2022-07-28T08:26:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tetsu](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@Tetsu](https://forum.alternetsoft.com/u/Tetsu)\
**Post date:** [July 28, 2022, 12:26pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/15 "2022-07-28T12:26:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![yevgeni.zolotko](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/yevgeni.zolotko/32/25_2.png) [@yevgeni.zolotko](https://forum.alternetsoft.com/u/yevgeni.zolotko)\
**Post date:** [July 29, 2022, 12:35pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/16 "2022-07-29T12:35:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tetsu](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@Tetsu](https://forum.alternetsoft.com/u/Tetsu)\
**Post date:** [July 29, 2022, 3:05pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/17 "2022-07-29T15:05:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yevgeni.zolotko](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/yevgeni.zolotko/32/25_2.png) [@yevgeni.zolotko](https://forum.alternetsoft.com/u/yevgeni.zolotko)\
**Post date:** [August 22, 2022, 9:29am UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/18 "2022-08-22T09:29:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tetsu](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@Tetsu](https://forum.alternetsoft.com/u/Tetsu)\
**Post date:** [August 22, 2022, 2:54pm UTC](https://forum.alternetsoft.com/t/how-to-run-matplotlib-python-script/315/19 "2022-08-22T14:54:21Z")

</div>

Thanks for the info. I appreciate it.
