C
C#•12mo ago
Shiv

Python code inside c#

Team , we have some python code which need to be run inside c# . There is link to that in https://github.com/pythonnet/pythonnet#embedding-python-in-net but when i tried,it is giving error as Runtime.PythonDLL was not set . Does anyone know how to handle this ?
GitHub
GitHub - pythonnet/pythonnet: Python for .NET is a package that giv...
Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET develo...
15 Replies
cap5lut
cap5lut•12mo ago
well, without seeing any code we can only say set it appropriately $code
MODiX
MODiX•12mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Shiv
ShivOP•12mo ago
how do i format this?
cap5lut
cap5lut•12mo ago
like that
Shiv
ShivOP•12mo ago
I think it went as a file..It got formatted but coundnt send
cap5lut
cap5lut•12mo ago
if u have the constant path u can also just set the property directly
Python.Runtime.Runtime.PyhtonDLL = @"C:\Users\AppData\Local\Programs\Python\Python312\python312.dll";
Python.Runtime.Runtime.PyhtonDLL = @"C:\Users\AppData\Local\Programs\Python\Python312\python312.dll";
but generally speaking, u didnt really read what u linked to right? i mean, it literally says in the first point that the environment variable for the path to the dll is called PYTHONNET_PYDLL, but u r modifying the PATH env var and u r missing the PythonEngine.Initialize(); call as well
Shiv
ShivOP•12mo ago
I tried PythonEngine.Initialize(); but got the same error.. using (Py.GIL()) now this is giving 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
cap5lut
cap5lut•12mo ago
well, u have to set the dll path correctly and call PythonEngine.Initialize(); according to their docs
Shiv
ShivOP•12mo ago
Ok got that now ... this worked ..thanks @cap5lut 🙂 last thing
cap5lut
cap5lut•12mo ago
u couldve saved urself some struggle by reading what u linked (thats what i did because i never used that library ;p)
Shiv
ShivOP•12mo ago
Python.Runtime.PythonException: 'No module named 'spacy'' should i download this spacy library to local ? Yes sometimes I overlook and trying out different unwanted things
cap5lut
cap5lut•12mo ago
i have next to no clue about python and absolutely no clue how that library works
Shiv
ShivOP•12mo ago
Even I am not into python ... so all this is new to me... 😄 let me figure out . thanks for sorting out the main problem 🙂
cap5lut
cap5lut•12mo ago
from brief reading and some foggy memories: basically u need to setup the virtual environment for the python stuff. that library seems to not download modules for u so u have to set up this stuff urself
Shiv
ShivOP•12mo ago
OK ok ...got it
Want results from more Discord servers?
Add your server