DllNotFoundException help with Pythonnet
Hello! I'm using Pythonnet to try to run some python code in C#, however no matter what I do it seems to say it cannot find a python dll. A great example is giving it an exact path and it failing.
which works perfectly fine if that were opened using run; however it prints off an error like this:
DllNotFoundException: Could not load C:\Users\(me)\anaconda3\python39.dll.";
. Any and all help would be appreciated, I just would like to get this going. I have a large project ahead of me I'd like to tackle and my very first required thing is already being a block. I've gone through countless stack overflow pages and tried countless things myself, even rebuilding the entire dll myself (per one pages 'fix'), but between work and chores I don't have much time to figure this out in a reasonable time span, so again, any help would be appreciated.24 Replies
The error could be a dependency of that dll not being found.
Do you have any experience with Pythonnet, and if you do would you happen to know how to reference those too; then? On documentation all it says to do is to set the Runtime.PythonDLL to it's value, and run PythonEngine.Initialize(). Any ideas if not?
I'm not familiar with it, sorry
Upon even further inspection, it's actually two errors.
Oh that's basically a field or static init blowing up. You might be running incompatible runtime or something
Are you using net core/6 etc or net framework? What is the requirement for this pythonnet?
Targeting .NET 4.7.2, and this says it supports Python from 3.7-3.11, I don't see anything related to C# version requirements; however this is the github page if that helps https://github.com/pythonnet/pythonnet (sorry for making you baby me 😓, I appreciate your help)
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...
The package is .NET Standard 2.0, so it should support even your outdated version of .NET Framework
If that's not the issue, have any other idea on what it could be? This is all I'm attempting to run, currently.
Could always ask in their repo: https://github.com/pythonnet/pythonnet/discussions
Also getting this error, it appears.
(to be honest, though, I question the very notion of using Python from C#)
yeah I wish I could just do it all in C#, I'm not very familiar with python* but some of the libraries I want to use are python exclusives by the looks of it so I don't have too much of a choice. I've tried many other paths that don't involve python in C#, but none have yielded any results.
Out of curiosity, what specific libraries do you want to use?
Besides NumPy?
Openai, Transformers. Attempting to make a GPT-2 bot, I'm a bit of an AI enthusiast, actually going to get a degree in machine learning.
And why not just do it all with Python?
I'm most familiar with C#, and I'd like to make it into a discord bot, with a lot of features, such as reading chats and using them as training data on a schedule, so it can train itself based on a channel's chat and speak in said channel with anyone with access. Doing all of these different things in a language I've never touched before seems a little... not just hard, but not sure if it's a smart idea. I know how to do everything excluding the actual GPT-2 stuff in C#, and the GPT-2 stuff is only half the fight. If I can do that half in python, and the other half in C#, then that's absolutely golden. Hence wanting to get this library to work 🤣
I'd probably write two separate apps tbh
One in Python that does the AI thingamajig
And a bot in C#
Then just
System.Diagnostics.Process.Start("ai-stuff.py")
or w/eHow would they communicate, is the question though? If I could get them to communicate that'd be great, and the only solution I can think of is local connection through TCP but that seems needlessly complicated compared to getting this to work no?
no way
Or, to make code from this example better,
Was busy working with what you sent, and got pretty far. All I've gotta say is that's pretty fucking cool. I appreciate all the help man, got it to log python outputs.
Nice
😄 Very much appreciated, I'll close the post assuming I can now. Thanks for all the help @phaseshift, and you too.