question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cannot find class in module

See original GitHub issue

Environment

  • Pythonnet version:3.0.0
  • Python version:3.8.3
  • Operating System:windows10
  • .NET Runtime:dotnet core 5.0

Details

  • get error:
Traceback (most recent call last):
  File ".\test.py", line 15, in <module>
    from MyApp  import Class1
ImportError: cannot import name 'Class1' from 'MyApp' (unknown location)
  • my config file:
{
  "runtimeOptions": {
    "tfm": "netcoreapp5.0",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "5.0.2"
    }
  }
}
  • python code
    from clr_loader import get_coreclr
    from pythonnet import set_runtime
    
    rt = get_coreclr("D:\\test\\BotTest\\test.runtimeconfig.json")
    set_runtime(rt)
    
    import clr
    import sys
    import System
    sys.path.append("D:\\test\\BotTest\\MyApp\\bin\\Debug\\net5.0")
    clr.FindAssembly("MyApp")
    
    clr.AddReference("MyApp")
    from System  import Console
    from MyApp  import Class1
  • c# code
using System;

namespace MyApp
{
    public class Class1
    {
        public static void f(){
            Console.WriteLine("zzz");
        }
    }
}
  • It seems that latest version does not work well for dotnet core

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ramymagdy-rmcommented, Dec 28, 2022

Hi everyone, i ran into this exception and found this post answering the question, hope it helps in my case, i have developed both programs python and dotnet in separate directories and imported the dotnet bin into python’s app dir and it works fine so far https://stackoverflow.com/a/63728744/12821529

1reaction
filmorcommented, Sep 10, 2021

Hmm… The issue is that Python just “imports” the MyApp directory as a “namespace package”, not sure why. If you rename it or run your program from a different path, it works just fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't Import Python Class
I am having an issue with Python imports. I created a module to conveniently import a few classes inside of the module with...
Read more >
Can't find classes in different module : IDEA-152998 - YouTrack
I have a large project which has quite few modules. Layout is Maven. I compile project typically from command line and then only...
Read more >
puppet - Could not find class, and yet it is there
When doing a puppet agent call from a new image, I'm getting a err: Could not find class custommod error. The module itself...
Read more >
Intellij can't find classes in same package
I am using Intellij Community and am having a strange issue. If a class depends on a class in the same package the...
Read more >
Can't find class when load model
Hello! I created, trained and saved my model MyModel in Jupiter as 'mymodel.pt'. But then I want to load it in another application....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found