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.net
Filter by
Sorted by
Tagged with
1 vote
0 answers
183 views

Pythonnet not free memory after python script called

I use pythonnet to call python script in C#(.NET 6, API app), everytime after called, the memory just increased, never freed. For now, the only way to free memory is call ShutDown(), but the behavior ...
walker's a's user avatar
0 votes
2 answers
444 views

Object initialization in Pythonnet

Let's assume I've the following C# class: public class Test { public double X; public double Y; } I want to use the above C# Test class from IronPython and as well from CPython (using ...
Wollmich's user avatar
  • 1,636
0 votes
1 answer
530 views

Pythonnet cann't load System.IO.Path (.net 6.0)

I use Python 3.10 and Net 6.0. And my C# code call Directory.GetFiles function from System.IO. When I call dll from python using Pythonnet, it showed cannot load type: System.IO.Path. Please provide ...
Jadeson Zang's user avatar
3 votes
0 answers
2k views

Failed to initialize Python.Runtime.dll using Spyder

I am having an issue using the pythonnet module within Spyder I am trying to use pythonnet within a program I am writing. I am using Spyder (5.2.2) that I have installed using Anaconda, running python ...
oli's user avatar
  • 31
1 vote
1 answer
180 views

Python.Runtime.dll not found in Azure Function(v4)

we have created an Azure function in the dotnet framework(.NET6) that processes some python scripts in runtime using pythonnnet which was embedded inside Numpy(3.7.1.28) - Nuget package. Locally ...
karmel's user avatar
  • 11
0 votes
1 answer
215 views

System.DllNotFoundExecption Error - PythonNet C# and Python3.8

I am interested to call my existing python 3.8 modules from an developed WPF Application(Net Core3.1). I did the following: I installed pythonnet with: pip install pythonnet Set environment paths in ...
Daniel's user avatar
  • 1
1 vote
0 answers
331 views

Fetching Tuple from python code with Python.NET library

I use Python.Net library to run python code from c# environment. My python function returns 4 integers in that way : return num1, num2, num3, num4 I have problem with fetching this data from c# code. ...
Daxter44's user avatar
  • 115
3 votes
1 answer
3k views

Failed to create a default .NET runtime which would have been "netfx" on this system

I am trying run a python script that is importing clr as below: import clr But i am getting the following error while executing the python scripts: Failed to create a default .NET runtime which would ...
Sada's user avatar
  • 39
1 vote
0 answers
151 views

Python.NET stuck and cannot exit after executing code

I am trying to use Python.NET library and just trying simple code below. I use dotnet 6 and python 3.8 for this. I am running in Mac OS Monterey with M1 chip. Both python and dotnet binaries are for ...
Bharata's user avatar
  • 725
0 votes
0 answers
72 views

Call a C# method with DTO as entered parameter in python

I am using pythonnet and import .Net dll without any problem, but I faced with new problem when I want to call a C# method with DTO as entered parameter not primitive type such as string,int,bool and ...
Davood Akbarikia's user avatar
1 vote
1 answer
631 views

Pythonnet - how to easily convert python object to c# object and vice versa

I'm using pythonnet package to use C# binaries in Python. I'm wondering what is the easiest way to convert a NET dcitionary/list/object to Python dictionary/list/object. The reason is that: a) To run ...
Jason's user avatar
  • 293
2 votes
1 answer
1k views

Issues using Pythonnet to embed Python Script within C#

I'm trying to use the pythonnet nuget package to embed Python 3.6.5 (32-bit) on .Net 6.0 but it throws the following exceptions: System.TypeInitializationException: 'The type initializer for '...
Shaunl322's user avatar
1 vote
1 answer
2k views

pywebview installing Error Python windows 10 (Python 3.10.5) "pip install pywebview"

On executing pip install pywebview i encountered this error.I want to view a webpage in python without using external browser. C:\Users\anik4\Desktop\New folder\Website Blocker> pip install ...
Anik Saha's user avatar
  • 105
1 vote
1 answer
551 views

AttributeError: module 'clr_loader' has no attribute 'wrappers'

I am trying use Beeware to package my python prjocet, but when I am trying to use "briefcase dev" command, It raise this error. I found that it need to use pythonnet and clr, and when it ...
Walter's user avatar
  • 21
2 votes
1 answer
1k views

Python.Net: how to execute modules in packages?

I'm not a Python programmer so apologies if I don't get some of the terminology right (pacakages, modules)! I have a folder structure that looks something like this: C:\Test\System\ C:\Test\System\...
Andrew Stephens's user avatar
2 votes
3 answers
512 views

Reset environment/scope between multiple function calls in Python.Net

I want to execute the same Python function several times and I want each execution to be completely isolated from the previous one. But the problem is that the first execution of the method changes a ...
Enrique's user avatar
  • 124
1 vote
0 answers
1k views

No module named clr

I have installed pythonnet with pip install pythonnet and I am trying to use clr by import clr. However, I get an error saying "no module named clr." Is there a problem with the directory I ...
String's user avatar
  • 109
0 votes
1 answer
340 views

Pythonnet TypeError when initializing class

I'm trying to access a class inside a .dll file using pythonnet and I am unable to create and instance of a class without the following error. I'm using the latest version of pythonnet (2.5.2) and ...
ssmith's user avatar
  • 1
0 votes
0 answers
338 views

Win32Exception: Access Denied when trying to embed Python into C# UWP Project

I am trying to run some Python scripts in my UWP project with pythonnet. After setting Runtime.PythonDLL equal to python38.dll path, PythonEngine.Initialize(); throws a 'System.DllNotFoundException'. ...
levente.nas's user avatar
0 votes
1 answer
303 views

Python can't find module for import

I have a dll file that I need to import in Python. However when I try to load the assembly I get the error: ModuleNotFoundError: No module named 'TEST_NET' The assembly dll file is located in C:\...
Sotomayor1989's user avatar
3 votes
2 answers
2k views

Python.Runtime.PythonException: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(int_value)

I recently moved my code to a new computer at work. A basic example code is as follows (but you wouldn't be able to run it as you can't connect to my server - sorry that I couldn't make it any more ...
bitterjam's user avatar
  • 129
0 votes
1 answer
560 views

System.Collections.Generic lists in Python 'TypeError: type(s) expeected' error

I am trying to run the following piece of code: import clr import sys #import System.Collections clr.AddReference("System.Collections") from System.Collections.Generic import List from ...
Justin Xuereb's user avatar
0 votes
1 answer
267 views

Installing Pythonnet package on MacOS v12.4

Has anyone installed Pythonnet on Python 3.10.0 (was pre-installed with Mac OS)? When I try to install Pythonnet through PIP, it complains that there is some issue with the package, and not with PIP!! ...
abinash7's user avatar
4 votes
1 answer
249 views

Can I use pythonnet without .AddReference?

The usual way to integrate pythonnet in your project is the following: import clr clr.AddReference('My.Assembly') import My.Assembly My.Assembly.DoSomething() What if I don't want the assembly ...
Ax_6's user avatar
  • 91
0 votes
1 answer
418 views

Cannot run Python script from C# due to missing "encodings" module with Pythonnet

I'm trying to run a Python module from within C# by using an existing (and working) virtualenv. I get ModuleNotFoundError: No module named 'encodings', maybe due to an incorrect loading of the Python ...
exrezzo's user avatar
  • 507
0 votes
0 answers
151 views

OpenCv error in function Circle. Works on python 3.9 but dont work on python 3.8

Hi i trying to run some python program for image analyse. I got configured environment on python 3.9 and there its works fine with anaconda, but now i need to run it on python 3.8 becouse i have to ...
Daxter44's user avatar
  • 115
5 votes
1 answer
2k views

How to add virtualenv to Pythonnet?

I am not able to load a virtual environment I have using virtual-env in the same directory as the C# file. Here is my code var eng = IronPython.Hosting.Python.CreateEngine(); var scope = eng....
Joseph Adam's user avatar
  • 1,482
1 vote
1 answer
883 views

In Pythonnet BeginAllowThreads crashes when calling C# object from Python

Using Pythonnet I'm calling a long-running method on a CLR object from within a Python script. I want to use BeginAllowThreads to allow other threads obtain the GIL as described here: Pythonnet ...
cjm1905's user avatar
  • 11
0 votes
1 answer
381 views

How to make WPF MVVM Bindings work in python.NET (Cpython)?

I'm trying to port this IronPython WPF example to CPython with python.NET. I'm able to get the window running after fixing some known issues (adding __namespace__ to the ViewModel class, using Single ...
sanzoghenzo's user avatar
3 votes
2 answers
2k views

Pythonnet importing class: "ModuleNotFoundError: No module named..."

I am importing a C# dll into python using pythonnet. import sys import clr assemblydir = r"C:\Users\Nathan_Dehnel\source\repos\TFSHygiene\bin\Debug\net5.0-windows" sys.path.append(...
Nathan Dehnel's user avatar
1 vote
1 answer
2k views

How can I use .NET dll in python?

I am having a weird error trying to use .NET dll in a python program. C:\temp>"c:\apps\WPy64-37120\pypy3.7-v7.3.7-win64\python.exe" example.py Failed to initialize pythonnet: System....
Alex Gdalevich's user avatar
1 vote
0 answers
182 views

ModuleNotFoundError: No module named 'CalcTestNS'

I am trying to read a DLL file using pythonnet library. The DLL file was generated using .NET framework 5.0 using the simple code below. using System; namespace CalcProcess { public class ...
Torch's user avatar
  • 71
0 votes
1 answer
388 views

TypeLoadException in Python while using Python.Net

I am using 2 .net class libraries in the Python using Python.Net Wanted to pass class object as parameter in a method call PT.cs using System; namespace Point { public class PT { ...
user18949149's user avatar
2 votes
3 answers
4k views

Pythonnet load clr-module - can add reference but cannot load namespace module

I am trying to load dlls into my python code. First of all, I installed the python package pythonnet py -3.8 -m pip install pythonnet I succeeded in using System.Array within my python code: import ...
StephanH's user avatar
  • 472
1 vote
1 answer
763 views

pythonnet: Convert System.Drawing.Bitmap to PIL.Image

I have a .net library which creates an image. I need access to this image in python so I'm trying to use pythonnet to call the .net DLL. I'm trying to use the following answer to convert the .NET ...
Ian Newson's user avatar
  • 7,857
1 vote
1 answer
557 views

Memory Management while embedding python in C# using python.net

I am trying to understand how memory is managed when python is embedded in C# using python.net. Python is executed in C# using the py.GIL (global interpreter lock), essentially C# calls the python ...
qwerty's user avatar
  • 897
2 votes
1 answer
498 views

How to call public method in .NET5 dll from RapsberryPi using Python 3.9

I have Win10 (64 bit) VS2019 C# .NET5 project. This project contains public method named "Add(int a, int b)" in public class "Calculate" in namespace "CsharpDll". Built ...
Antti's user avatar
  • 21
1 vote
0 answers
641 views

pyinstaller + pythonnet(clr): module not found after adding dll as reference

I'm trying to pack a some code from me into an exe with help of pyinstaller. In the code I use some proprietary .net third party libraries which are included with the pythonnet/clr module. If I run ...
dominikdh's user avatar
1 vote
1 answer
1k views

Multithreading with python.net

I am calling python from C# using the following code: if (!PythonEngine.IsInitialized) { PythonEngine.Initialize(); PythonEngine.BeginAllowThreads(); } //var pythonScriptCommand = string....
qwerty's user avatar
  • 897
2 votes
1 answer
277 views

how can i Embed python module in .net?

I have made a Ai cursor controller by face land marks by using python open cv, So i need to use this module inside my web browser application that made from .net c# chromium framework. How can i do ...
Lahiru Tharaka's user avatar
0 votes
1 answer
581 views

Pythonnet (clr) and C# lists and enums

I have myClass which contains a field myList which is a list of elements from myEnum. I would like to add to this list more elements but in python. However exec(f"myClass.myList.Add(myEnum.{e}))&...
Cugusek's user avatar
0 votes
1 answer
72 views

convert stored()[:10] function in python to .net syntax (pythonnet)

I have python script and I try to rewrite it using pythonnet in .net. This But i confuse how to convert this line in python to .net? contours = sorted(contours, key = cv2.contourArea, reverse = True)[...
nawar's user avatar
  • 63
1 vote
1 answer
169 views

Winforms (with Python): Drag file object to Windows Explorer

I am using WinForms with Python / pythonnet. I have a WinForm object and want to drag the underlying file data to Windows Explorer. I basically do this: def on_mouse_down(self, sender, event): ...
Nayaro's user avatar
  • 117
1 vote
1 answer
447 views

Which process runs python script running through python.net in C#

I have the following script. try { PythonEngine.Initialize(); using (Py.GIL()) { using (PyScope scope = Py....
qwerty's user avatar
  • 897
1 vote
2 answers
5k views

Executing Python Script from Windows Forms .NET

I am fairly new to Python and .NET in general, but decided to ask more competent people, since I have been struggling with the issue of executing python script from Windows Forms. The basic idea of my ...
Dobromir Dobrev's user avatar
0 votes
0 answers
150 views

TypeError on calling C# .dll API from python using pythonnet

I am trying to call C# APIs from python script, while doing so, I face TypeError, saying the API, that I am trying to call via python doesn't exist. I have verified the .dll to be present in the path, ...
user13252's user avatar
0 votes
0 answers
240 views

Python.NET garbage collection

I try to integrate an external C# Library in a Python project. The library reads and converts some file contents that I want to consume in Python and then delete the file: import clr from pathlib ...
user106745's user avatar
0 votes
1 answer
589 views

Can you check python code in csharp before pythonNet execution?

i have recently started using pythonNet for executing scripts from Csharp, on an algorithm i was doing in csharp up until now, it works pretty well: using (Py.GIL()) { PythonEngine.Initialize(); ...
Bad_deepLearner's user avatar
0 votes
0 answers
210 views

Why am I getting System.PlatformNotSupportedException when using SqlClient?

I'm using the current master branch of Python.Net 3.0 from GitHub, on Python 3.10, on Windows 10. I wrote a test DLL in .NET 5 that uses System.Data.SqlClient to perform a single call to a SQL Server ...
downshiftdata's user avatar
2 votes
0 answers
1k views

Installation of PythonNet in Visual Studio 2019 throw System.TypeInitializationException , DllNotFoundException

Currently trying out pythonNet to see how easy it is to call python code from csharp, I would have gone for ironpython but I have read that you can't choose a 3.x python version, which can be limiting....
Bad_deepLearner's user avatar

1 2
3
4 5
13