Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 11:07
    filmor commented #330
  • 09:25
    stonebig commented #330
  • Jun 11 22:40
    nao20010128nao starred pythonnet/pythonnet
  • Jun 11 19:40
    pkese commented #1466
  • Jun 11 19:25
    drahnreb starred pythonnet/pythonnet
  • Jun 11 18:28
    mathias7777 starred pythonnet/pythonnet
  • Jun 11 18:27
    tsukumijima starred pythonnet/pythonnet
  • Jun 11 12:56
    filmor closed #1466
  • Jun 11 12:56
    filmor commented #1466
  • Jun 11 10:12

    lostmsu on master

    Add a failing test for Unicode … Fix Python -> .Net unicode stri… Add separate test for the initi… and 6 more (compare)

  • Jun 11 10:12
    lostmsu closed #1467
  • Jun 11 09:42
    lostmsu commented #1467
  • Jun 11 09:40
    filmor commented #1467
  • Jun 11 05:28
    filmor synchronize #1467
  • Jun 11 05:19
    filmor closed #1470
  • Jun 11 05:19
    filmor commented #1470
  • Jun 10 17:00
    billsioros starred pythonnet/pythonnet
  • Jun 10 13:19
    exec-life starred pythonnet/pythonnet
  • Jun 10 03:52
  • Jun 09 16:58
    pkese synchronize #1467
chanyam
@chanyam:matrix.org
[m]

Hi! Using Pythonnet with Python 3.7 to load a .NET assembly, which seems to work just fine, but when I try to import an object from a namespace in that assembly, I get this error:

Traceback (most recent call last):
File "ForzaTextureExporter", line 10, in
File "E:\Tools\Scripts\Houdini\python\hdi\TextureExporter.py", line 38, in main
from MetaDataObjects import TextureSourceMetadataFactory
ModuleNotFoundError: No module named 'MetaDataObjects'

The assembly I'm loading has a bunch of external references to some of our other assemblies, but even copying those dlls into the same dir as python37.exe doesn't seem to get me past this.

the code I'm using is pretty straight forward:
assemblyPath = r"C:\python37" #moved all assemblies here, where python37.exe is
lib = clr.AddReference(os.path.join(assemblyPath, "ContentBrowserMetadataObjects"))
from MetaDataObjects import TextureSourceMetadataFactory # errors out here

Oh god, sorry about the formatting!
chanyam
@chanyam:matrix.org
[m]

:point_up: Edit: Hi! Using Pythonnet with Python 3.7 to load a .NET assembly, which seems to work just fine, but when I try to import an object from a namespace in that assembly, I get this error:

Traceback (most recent call last):
File "ForzaTextureExporter", line 10, in
File "E:\Tools\Scripts\Houdini\python\hdi\TextureExporter.py", line 38, in main
from MetaDataObjects import TextureSourceMetadataFactory
ModuleNotFoundError: No module named 'MetaDataObjects'

The assembly I'm loading has a bunch of external references to some of our other assemblies, but even copying those dlls into the same dir as python37.exe doesn't seem to get me past this.
The code I'm using is pretty straight forward:

assemblyPath = r"C:\python37" #moved all assemblies here, where python37.exe is
lib = clr.AddReference(os.path.join(assemblyPath, "ContentBrowserMetadataObjects"))
from MetaDataObjects import TextureSourceMetadataFactory # errors out here

slide-o-mix
@slide-o-mix:matrix.org
[m]
MetaDataObjects is the namespace?
chanyam
@chanyam:matrix.org
[m]
sorry, yes
chanyam
@chanyam:matrix.org
[m]
OMG - I just realized this looking at your question slide-o-mix
Its MetadataObjects 🤦‍♂️
thanks for pointing that out - for some reason my brain wasn't seeing it until just now
slide-o-mix
@slide-o-mix:matrix.org
[m]
It works with the correct namespace?
chanyam
@chanyam:matrix.org
[m]
yeah. i wouldn't call this a high point in my coding career, but hey, its working :D
slide-o-mix
@slide-o-mix:matrix.org
[m]
happens to everyone...
IamMusavaRibica
@IamMusavaRibica

How to write this method in pythonnet?

public override T[] ReadArray<T>(Func<T> func1)  {
     var count = ReadUInt32();
     var arr = new T[count];
     for (var i = 0; i < count; i++)  {
          arr[i] = (func1.Invoke());
     }
     return arr;
}

Its all happening in System.IO.BinaryReader and the func1 passed is System.IO.BinaryReader.ReadByte

chanyam
@chanyam:matrix.org
[m]
chanyam
@chanyam:matrix.org
[m]

OK, I'm getting the 'Module not found" errors again (and I've doubled checked my spelling :D)

It worked for a while on Friday and now after the weekend, its stopped. I haven't changed anything in my environment afaik. As a sanity check, I decided to print the assembly's ExportedType property to see what exactly was available from our assembly post-load. My code looks like this:

cblib = clr.AddReference(os.path.join(assemblyPath, "ContentBrowserMetadataObjects"))
    if cblib == None:
        print("failed to load ContentBrowserMetadataObjects.dll from " + assemblyPath)
    else:
        print("Successfully loaded ContentBrowserMetadataObjects.dll from " + assemblyPath)
    print(cblib.ImageRuntimeVersion)
    for t in cblib.ExportedTypes:
        print(t)

When I try calling cblib.ExportedTypes, I get the following exception message:

File "ForzaTextureExporter", line 9, in <module>
File "E:\P4\FMBase_Main\Tools\Scripts\Houdini\python\hdi\Forza_TextureExporter.py", line 26, in main
for t in cblib.ExportedTypes:
System.IO.FileNotFoundException: Could not load file or assembly 'Autofac, Version=4.0.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The system cannot find the file specified.
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()

So where is it looking for Autofac? I used Procmon to find all the events related to Houdini (the app calling Python3.7) and right after the event where it loads our assembly (ContentBrowserMetadataObjects.dll) I see the event in the image posted above. It looks like it took the Autofac assembly header and is using it for the name? If i copy Autofac.dll into that dir, it still complains about not finding the dll, but if I copy the name in the event (Autofac, Version=4. etc, etc) and rename the assembly to that, then it works - which is to say that it gets past the Autofac assembly reference but then dies on the next assembly reference, where it does the same thing (uses the header as the assembly name and not finding the dll). Does anyone know how pythonnet resolves assembly references?

chanyam
@chanyam:matrix.org
[m]
I assume this is why copying all of our assemblies into the same folder as the python3.7 exe didn't work - its looking for these modified named assemblies instead of the original assembly names.
chanyam
@chanyam:matrix.org
[m]

:point_up: Edit: OK, I'm getting the 'Module not found" errors again (and I've doubled checked my spelling :D)

It worked for a while on Friday and now after the weekend, its stopped. I haven't changed anything in my environment afaik. As a sanity check, I decided to print the assembly's ExportedType property to see what exactly was available from our assembly post-load. My code looks like this:

cblib = clr.AddReference(os.path.join(assemblyPath, "ContentBrowserMetadataObjects"))
    if cblib == None:
        print("failed to load ContentBrowserMetadataObjects.dll from " + assemblyPath)
    else:
        print("Successfully loaded ContentBrowserMetadataObjects.dll from " + assemblyPath)
    print(cblib.ImageRuntimeVersion)
    for t in cblib.ExportedTypes:
        print(t)

When I try calling cblib.ExportedTypes, I get the following exception message:

File "ForzaTextureExporter", line 9, in <module>
File "E:\P4\FMBase_Main\Tools\Scripts\Houdini\python\hdi\Forza_TextureExporter.py", line 26, in main
for t in cblib.ExportedTypes:
System.IO.FileNotFoundException: Could not load file or assembly 'Autofac, Version=4.0.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The system cannot find the file specified.
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()

So where is it looking for Autofac? I used Procmon to find all the events related to Houdini (the app calling Python3.7) and right after the event where it loads our assembly (ContentBrowserMetadataObjects.dll) I see the event in the image posted above. It looks like it took the Autofac assembly header and is using it for the name? If i copy Autofac.dll into any of the dozen paths that procmon tells me the assembly resolver is looking for Autofac in, it still complains about not finding the dll, but if I change the name of the assembly from 'Autofac.dll' to 'Autofac, Version=4.0.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da.dll', then it works - which is to say that it gets past the Autofac assembly reference but then dies on the next assembly reference, where it does the same thing (uses the header as the assembly name and not finding the dll). Does anyone know how pythonnet resolves assembly references?

chrisquin
@chrisquin:matrix.org
[m]
hello, i try to use a .net dll and got an error:
System.TypeLoadException: Could not resolve type with token 010000c5 from typeref (expected class 'System.Diagnostics.Debug' in assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
i am running a python script on linux that uses a dll which uses a simple Debug.WriteLine(...)
does somebody has an idea what is wrong? Perhaps install additional libs/packages? I installed Mono like mentioned here (https://www.mono-project.com/download/stable/)
chrisquin
@chrisquin:matrix.org
[m]
or how to install System.Diagnostics with gacutil
chrisquin
@chrisquin:matrix.org
[m]
dead chanel?
slide-o-mix
@slide-o-mix:matrix.org
[m]
System.Diagostics should be available as part of Mono
chrisquin
@chrisquin:matrix.org
[m]
it isn't. tried to install by my own: nuget install System.Diagnostics.Debug and then gacutil -i System.Diagnostics.Debug.dll but got the error:
Failure adding assembly System.Diagnostics.Debug.dll to the cache: Strong name cannot be verified for delay-signed assembly
chrisquin
@chrisquin:matrix.org
[m]

i tried to use dotnet under linux and installed the master pythonnet master into my virtual python 3.8 environment.
I exceuted the following code:

from clr_loader import get_coreclr
import pythonnet

rt = get_coreclr("runtimeconfig.json")
pythonnet.set_runtime(rt)
pythonnet.load()

import System
from System import String

s = String("Hello World from Python.NET for .NET 5!")
System.Console.WriteLine(s)

import clr

my_module = clr.AddReference("GWconfig")
from GWconfig import cls

with the runtimeconfig.json:

{
  "runtimeOptions": {
    "tfm": "net5.0",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "5.0.5"
    }
  }
}

with dotnet:

dotnet --list-runtimes
Microsoft.AspNetCore.App 5.0.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Now i got the error:

ModuleNotFoundError: No module named 'GWconfig'

and:

my_module.DefinedTypes
*** System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

Could not load file or assembly 'System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

...

does somebody have an idea?

chendingqi
@chendingqi
ucrtbase.dll error???
how to slave
how to solve
rookenhiem
@rookenhiem:matrix.org
[m]
im trying to install this on ubuntu and have no idea how to do this , can anyone help? i tried installing dependencies but they all threw up and error
slide-o-mix
@slide-o-mix:matrix.org
[m]
rookenhiem: Are you compiling from source yourself?
P.E Lim
@PeiErnLim95

Hey guys, so I keep getting the

System.TypeInitializationException: The type initializer for 'Delegates' threw an exception.
 ---> System.MissingMethodException: Did you forget to set Runtime.PythonDLL? See https://github.com/pythonnet/pythonnet#embedding-python-in-net
 ---> System.MissingMethodException: Failed to load symbol PyDictProxy_New

error, I have already reference the Python Runtime dll in my C# project and also install the pythonnet nuget package, what am I missing?

hh-wu
@hh-wu
Hello, I am trying to call a function of a COM object 'oApp', does anyone know how can I call it?
oApp.GetDynamicMemberNames()
['DisableProfiling', 'EnableProfiling', 'GetApp', 'GetAppDesktop', 'GetEnableGPUforDSO', 'GetEnableOptimetricsDistributionUsingDSOLicense', 'GetExternalLink', 'GetExtractorDesktop', 'GetNumberOfProcessorsDistributed', 'GetNumberOfProcessorsPostProc', 'IsInteractiveDesktop', 'LaunchSPISim', 'ReleaseDesktopPtr', 'SetEnableGPUforDSO', 'SetEnableOptimetricsDistributionUsingDSOLicense', 'SetNumberOfProcessorsDistributed', 'SetNumberOfProcessorsPostProc']
oApp is "IDispatch(IAnsysEDTComInterfaceV2021_1)"