Questions tagged [python.net]

Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and Mono. Pythonnet provides a powerful application scripting tool for .NET developers. Using this package you can script .NET applications or build entire applications in Python, using .NET services and components written in any language that targets the CLR (C#, VB.NET, F#, C++/CLI) and CPython.

Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and Mono. Pythonnet provides a powerful application scripting tool for .NET developers. Using this package you can script .NET applications or build entire applications in Python, using .NET services and components written in any language that targets the CLR (C#, VB.NET, F#, C++/CLI) and CPython.

https://pythonnet.github.io/

578 questions
7
votes
4 answers

Import of DLL with pythonnet

I am trying to import and use a DLL in python. Therefore I am using pythonnet. import sys import clr sys.path.append('C:\PathToDllFolder') clr.AddReference('MyDll.dll') However the code yields the following error: Traceback (most recent call…
MJA
  • 357
  • 2
  • 5
  • 10
7
votes
1 answer

Python for .NET: How to explicitly create instances of C# classes using different versions of the same DLL?

I have a .cs file like namespace SomeNamepace { public struct SomeStruct { .... } public static class SomeClass { .... } So far I use it with PythonNET like import…
Joe
  • 6,758
  • 2
  • 26
  • 47
7
votes
1 answer

Calling C# code within Python3.6

with absolutely no knowledge of coding in C#, I wish to call a C# function within my python code. I know there's quite a lot of Q&As around the same problem, but for some strange reason, i'm unable to import a simple c# class library from a sample…
Skanda Avadhani
  • 153
  • 1
  • 7
6
votes
1 answer

Replace IronPython with Python.Net?

We've been using IronPython for a number of years as a scripting tool within some of our .Net desktop applications. Customers have been asking when we will support Python 3, but it looks like IronPython3 is still a long way off…
Andrew Stephens
  • 9,413
  • 6
  • 76
  • 152
6
votes
4 answers

No module named 'System'

I have an issue that has been discussed in some GitHub blogs but the answers there are so confusing and complex that I thought to ask here as well. Before asking, let me just say I'm not an expert programmer, so my apologizes if mine is a simple…
Angelo
  • 1,594
  • 5
  • 17
  • 50
6
votes
1 answer

Python NET call C# method which has a return value and an out parameter

I'm having the following static C# method public static bool TryParse (string s, out double result) which I would like to call from Python using the Python NET package. import clr from System import Double r0 = Double.IsNaN(12.3) # works r1, d1 =…
Wollmich
  • 1,616
  • 1
  • 18
  • 46
6
votes
2 answers

Call python script from .Net Core using pythonnet

I'm trying to get pythonnet to work in my .Net Core app running on Linux. I've made a reference to Python.Runtime.dll (which I got from nuget) in my .Net Core project. My code is: using System; using Python.Runtime; namespace pythonnet_w { class…
MrCalvin
  • 1,675
  • 1
  • 19
  • 27
6
votes
2 answers

Python tkinter.filedialog askfolder interfering with clr

I'm mainly working in Spyder, building scripts that required a pop-up folder or file Browse window. The code below works perfect in spyder. In Pycharm, the askopenfilename working well, while askdirectory do nothing (stuck). But, if running in debug…
Itzik Kaplan
  • 63
  • 1
  • 6
6
votes
1 answer

Python .NET, multithreading and the windows event loop

I'm building a Python API around a black box .NET DLL using Python .NET. The DLL is only doing networking operations. The DLL require me to run a windows message pumping loop, otherwise the network operations get stuck after a while. I run the…
Gijs Molenaar
  • 405
  • 1
  • 3
  • 9
6
votes
0 answers

Calling .NET library function from Python

I am almost at the end of my wits here and am hoping you all could help me figure this one out. I am running Anaconda Python 3.5 64 bit and compiled Python.NET anaconda package to add .NET capabilities to Python. I imported a DLL sent to me by…
A Saxena
  • 165
  • 2
  • 13
6
votes
3 answers

Efficiently convert System.Single[,] to numpy array

Using Python 3.6 and Python for dotNET/pythonnet I have manged to get hold of an image array. This is of type System.Single[,] I'd like to convert that to a numpy array so that I can actually do something with it in Python. I've set up a function to…
rbp109
  • 131
  • 1
  • 6
6
votes
1 answer

How to handle exception in using(Py.GIL()) block pythonnet

Is there a way to handle exceptions in using the (Py.GIL()) block? For example: using System; using Python.Runtime; public class Test{ public static void Main(){ using(Py.GIL()){ try{ …
ash
  • 2,902
  • 3
  • 19
  • 34
6
votes
2 answers

Convert C# byte array to numpy array in Python .Net

I try to use a .NET Assembly in a python application using Python.NET. The C# code captures an image, that i want to use with python. Let's say I have the following C# method: public static byte[] Return_Image_As_Byte_Array() { Image…
aPere
  • 71
  • 1
  • 6
6
votes
1 answer

for scriptcs `dynamic` is not supported by Roslyn and available only with mono, but mono fails on DLL

I'm try to load pythonnet runtime dll from scriptcs and it does not work with roslyn backend because dynamic is not supported in Roslyn, but mono backend chokes with the following error: $ scriptcs -modules mono scriptcs (ctrl-c to exit or :help for…
denfromufa
  • 5,610
  • 13
  • 81
  • 138
6
votes
2 answers

Python for .NET

I have a problem loading an external dll using Python through Python for .NET. I have tried different methodologis following stackoverflow and similar. I will try to summarize the situation and to describe all the steps that I've done. I have a dll…
user3075816
  • 169
  • 1
  • 11