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
6
votes
1 answer

Using System.Collections.Generic.List`1[System.Byte] in Python

I have a Python script which receives data from a .NET application. How do I use an incoming buffer of type 'System.Collections.Generic.List`1[System.Byte]' in my script? The function of the script would be to find and replace string tokens,…
AKK2015
  • 61
  • 1
  • 2
6
votes
3 answers

Creating a C# Nullable Int32 within Python (using Python.NET) to call a C# method with an optional int argument

I'm using Python.NET to load a C# Assembly to call C# code from Python. This works pretty cleanly, however I am having an issue calling a method that looks like this: A method within Our.Namespace.Proj.MyRepo: OutputObject GetData(string user, int…
skulz00
  • 769
  • 8
  • 18
6
votes
1 answer

How to unload a .NET assembly reference in IronPython

After loading a reference to an assembly with something like: import clr clr.AddRferenceToFileAndPath(r'C:\foo.dll') How can I unload the assembly again? Why would anyone ever want to do this? Because I'm recompiling foo.dll and want to reload it,…
Daren Thomas
  • 67,947
  • 40
  • 154
  • 200
6
votes
2 answers

The definitive method to use NumPy and SciPy from IronPython

There is a way to use NumPy/SciPy in IronPython, using IronClad to execute/communicate with the CPython binaries of the same. A newer project, Python Tools for VS allows for a faster integration with .NET IronPython programs because most of the…
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
5
votes
1 answer

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.CreateScope(); // Load Virtual Env ICollection
Joseph Adam
  • 1,341
  • 3
  • 21
  • 47
5
votes
0 answers

python.net inconsistant automatic type conversion

We are using python.net console embedded with our application. On a specific machine running the python console the automatic type conversion defaults to the base class of the object and not the actual type. On all the other test machine this works…
vwpora
  • 87
  • 6
5
votes
3 answers

Pip Pythonnet option --single-version-externally-managed not recognized

Trying to install pythonnet 2.4.0 on Ubuntu 18.04 Bionic on Windows WSL, I get following error. Mono version installed is 5.20.1.34 and Python 3.6 ---------------------------------------- Failed building wheel for pythonnet Running setup.py…
carraua
  • 1,398
  • 17
  • 36
5
votes
0 answers

How to modify StartupPath through Pythonnet

I have a bundle of C# DLLs that I am trying to wrap with python using the pythonnet library. I noticed that the DLLs are using Application.StartupPath, which in python's case is where the python.exe is located (as far as I understand). This is…
bgmoshe
  • 61
  • 6
5
votes
0 answers

Running Python 3.7 from C# using Python .NET

I am trying to include a sample script (the one provided in the README.md) into a test C# code in Visual Studio 2019. I am using a Python virtualenv. Some information on my environment: Pythonnet version:…
Andrea
  • 4,262
  • 4
  • 37
  • 56
5
votes
1 answer

Connecting to Siemens NX server from python (NXOpen); pythonnet GetObject TypeError

I am trying to grab the Session object from a Siemens NX server (on the same machine, i.e. localhost). I am using python 3.6 with pythonnet, since the remote connection (apparently) only works through .NET - I am VERY new to pythonnet (only tried…
Jakob Müller
  • 91
  • 1
  • 8
5
votes
1 answer

Use .Net (C#) dll in Python script

I'm attempting to port a simple C# command-line utility to Python. The C# program uses a custom .Net dll called foobar.dll that interfaces with some lab equipment via I2C. The usage of the dll in the C# code is as follows: fooBar.fooProvider…
chisaipete
  • 884
  • 9
  • 20
5
votes
1 answer

Handle Python pickle bytes object in C#

Using Pythonnet in a C# application: Python returns a bytes ({}) object which is the result of a pickle.dumps operation. What is the best way of dealing with this object in C# in terms of persistance to blob storage and rehydrating a…
cillierscharl
  • 7,043
  • 3
  • 29
  • 47
5
votes
1 answer

Wrapping Microsoft Dynamics Business Connector .net assembly in python

I am writing a python wrapper to the Microsoft Dynamics Business Connector .net assembly. This is my code: """Implements wrapper for axapta business connector.""" import pathlib from msl.loadlib import LoadLibrary import clr DLL_PATH =…
zhukovgreen
  • 1,551
  • 16
  • 26
5
votes
2 answers

pythonnet Embedding Python in .net example failing to load module

I'm trying to run the Embedding Python in .NET example from https://github.com/pythonnet/pythonnet. I've followed troubleshooting articles to set the proper %PYTHONPATH% and %PYTHONHOME% to my anaconda environment in the program base…
mstockfo
  • 91
  • 1
  • 8
5
votes
1 answer

Calling C# code from python using pythonnet

Following is the C# code. How do I call the GenericMethod() inside the NonGenericClass from Python using pythonnet? namespace CSharpTestCode { public interface Person { } public class Employee : Person { } public class…
Developer
  • 103
  • 2
  • 10