Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

DllNotFoundException on .net 6 with python 3.12#2340

Unanswered
software6ptk asked this question inQ&A
Discussion options

Environment

  • Pythonnet version: 3.0.3
  • Python version: 3.12
  • Operating System: Windows 11 pro
  • .NET Runtime: 6

Details

I am trying to setup pythonnet to run some python scripts in my c# app, but i'm getting the usual DllNotFoundException when setting the Runtime.PythonDLL variable

If i'm not wrong, both the python version and the .net runtime are supported so that shouldn't be the issue
image
image

this is what i do

stringdllpth=Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);dllpth+="\\Local\\Programs\\Python\\Python312\\python312.dll";Runtime.PythonDLL=dllpth;PythonEngine.Initialize();

i also tried

stringdllpth=Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);dllpth+="\\Local\\Programs\\Python\\Python312\\python312.dll";Environment.SetEnvironmentVariable("PYTHONNET_PYDLL",dllpth);PythonEngine.Initialize();

Errors are:

System.TypeInitializationException: 'The type initializer for 'Delegates' threw an exception.'Win32Exception: Impossibile trovare il modulo specificato.

and

System.TypeInitializationException: 'The type initializer for 'Delegates' threw an exception.'DllNotFoundException: Could not load C:\Users\***\AppData\Roaming\Local\Programs\Python\Python312\python312.dll.

with details:

System.TypeInitializationException  HResult=0x80131534  Messaggio=The type initializer for 'Delegates' threw an exception.  Origine=Python.Runtime  Analisi dello stack:   in Python.Runtime.Runtime.<>c.<Initialize>b__32_0()   in Python.Runtime.Runtime.TryUsingDll[T](Func`1 op)   in Python.Runtime.Runtime.Initialize(Boolean initSigs)   in Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs)   in GeometriesVisualizer_EYESHOT.ScriptManager.RunLoaded(Object parameter) in C:\Users\***\ScriptManager.cs: riga 146   in GeometriesVisualizer_EYESHOT.MainWindow..ctor() in C:\Users\***\MainWindow.xaml.cs: riga 124   in System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)Eccezione interna 1:DllNotFoundException: Could not load C:\Users\***\AppData\Roaming\Local\Programs\Python\Python312\python312.dll.Eccezione interna 2:Win32Exception: Impossibile trovare il modulo specificato.

I already tried:

  • reinstalling python
  • changing build target to x64

I also searched online for a solution, but can't find anything besides changing the build target

Can you please help me?

You must be logged in to vote

Replies: 5 comments 2 replies

Comment options

For Python x64 use x64 profile app (Any CPU - not working)

You must be logged in to vote
0 replies
Comment options

Is there a chance you're just not installing the package correctly?

# from your .csproj directorydotnet add package pythonnet

Or possibly Python itself? Sounds like Python wasn't added to your environment PATH variables. OurStock Indicators for Python QuickStart may help with more details on how to setup your environment, though our use case is a bit different.

You must be logged in to vote
0 replies
Comment options

Hey,@software6ptk , did you solve the problem?

You must be logged in to vote
0 replies
Comment options

I'm having ecapt same issue. Weird thing is that on my dev computer, I got it working. Then I updated my app's Flight in MS store and tested with my laptop: getting the dllNotFound whatever I do. Tried several different versions and also checked that maybe the python38.dll (or 310.dll) has some dependency missing, but no...

You must be logged in to vote
1 reply
@mpulukkinen
Comment options

Actually, my issue was that one of the dependencies, msvc was not installed in target machine. I discovered when I ditched the pythonnet and starter running python just with process.start. So, it was actually one of the python scripts that failed to load the dll, but pythonnet completely "ate" the original error and made it look like the pythonnet.dll had some missing dependency. Pretty common case with c# and dependency dll load issues: the actual root cause gets lost in translation 😆

Comment options

static void Main(string[] args){    Runtime.PythonDLL = @"python313.dll";    PythonEngine.Initialize();    using (Py.GIL())    {        // Import TensorFlow preprocessing script        string modulePath = @"D:\ocr_v1\ConsoleApp1\ConsoleApp1\AiNet";        dynamic sys = Py.Import("sys");        sys.path.append(modulePath);        // Import your Python module and use it        dynamic utils = Py.Import("utils");        // Process image and run model prediction        string imagePath = "D:\\ocr_v1\\ConsoleApp1\\ConsoleApp1\\AiNet\\20160805-130.webp";        dynamic result = utils.detect_and_process_id_card(imagePath);        Console.WriteLine($"Predicted Class: {result}");    }    PythonEngine.Shutdown();}

I used something like that and worked to me and I create configuration manger of X64 to be combatable with with my vs and here where python liveC:\Users\User\AppData\Local\Programs\Python\Python313

You must be logged in to vote
1 reply
@sharafabacery
Comment options

Capture15

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
6 participants
@software6ptk@DaveSkender@Gianmaria92@sharafabacery@izhgtumekhanik@mpulukkinen
Converted from issue

This discussion was converted from issue #2339 on March 12, 2024 11:25.


[8]ページ先頭

©2009-2025 Movatter.jp