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

How to specify a .NET 4.8 runtime in pythonnet 3.x?#2005

Unanswered
pd185112 asked this question inQ&A
Discussion options

I'm trying to use pythonnet.3.0.1 to load/use a DLL in Python code that is compiled to require a .NET 4.8 (Target Framework: 4.8). Loading DLL doesn't work (ModuleNotFoundError: No module named 'DllThatRequires4.8'). I'm able to load a DDL from the same path that doesn't require .NET 4.8 (Target Framework: 4.0).

I suspect my issue is that pythonnet doesn't target the 4.8 runtime (see undefined runtime version in code output), how can I configure it to do so? I've found some examples of loading a .NET core with config:https://learn.microsoft.com/en-us/dotnet/core/runtime-config/#runtimeconfigjson, but nothing on legacy .NET.

My Windows Server 2016 machine has a .NET 4.8 installed, as shown under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\Version: 4.8.03761
Using Windows server 2016, python 3.10.8 32-bit, pythonnet 3.0.1

My code (simplified):
from pythonnet import get_runtime_info
sys.path.append('path\to\dll\folder')
import clr
print(get_runtime_info())
clr.AddReference('DllThatRequires4.8')
from DllThatRequires4.8 import something #this doesn't work
clr.AddReference('DllThatDoesNotRequire4.8')
from DllThatDoesNotRequire4.8 import something # this works

code output:
image

....
File "steps\Automation\client.py", line 8, in
from DllThatRequires4.8 import something
ModuleNotFoundError: No module named 'DllThatRequires4.8'

You must be logged in to vote

Replies: 1 comment 4 replies

Comment options

The runtime version is just not implemented (yet) for .NET Framework. If .NET 4.8 is installed, it should be used (I think :)). You could try to modifyclr_loader here,https://github.com/pythonnet/clr-loader/blob/master/netfx_loader/ClrLoader.csproj, to requirenet48.

You must be logged in to vote
4 replies
@pd185112
Comment options

Curious thing though, the setup described above is an attempt to upgrade the test environment running on Python 3.7.9/pythonnet 2.4.0 for a good while. This outdated setup works with 4.8 DLLs as expected, and I tried to jump versions directly to Python 3.10.8 32-bit/ pythonnet 3.0.1.
When I tried Python 3.7.9/pythonnet 2.5.0 combo to run the code passing on 2.4.0, the issue described above was reproduced. So it's not a problem exclusive to 3.0.x as I originally assumed.

@filmor
Comment options

Hmm, I don't think there were any significant changes between 2.4 and 2.5, just cleanups and additional code, seev2.4.0...v2.5.0. In particular, none of the changes touch the target frameworks, as far as I can tell. Can you try to create a minimal DLL that exhibits the behaviour?

@pd185112
Comment options

Sorry for delay in replying. I, along with some colleagues, were trying to find the root cause, but no joy so far.
You're correct, minimum DLLs didn't confirm the original assumption with .NET version. Besides, I found one other production library that requires .NET 4.8 and that one is loaded by pythonnet 3.x as expected.
The issue still persists with production libraries though. I had to switch to another task for the moment, but we'll return to this in the next sprint. If you happen to have any other theories, feel free to suggest things to try out...

@YoshiyasuIzumi
Comment options

Sorry for my interruption, but I assume I also faced same issue. In my case I prepared wrapper C# DLL to be called from Pythonnet as workaround. I understand this is not best way but I hope this help.
#2558 (reply in thread)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
3 participants
@pd185112@filmor@YoshiyasuIzumi

[8]ページ先頭

©2009-2025 Movatter.jp