cannot find class in module
See original GitHub issueEnvironment
- 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:
- Created 3 years ago
- Comments:15 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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.