Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'xxx' and NameError: name 'xxx' is not defined #468

Open
y1y2 opened this issue Jan 15, 2025 · 2 comments

Comments

@y1y2
Copy link

y1y2 commented Jan 15, 2025

I called python in kotlin and started reporting ModuleNotFoundError: No module named 'xxx'.
I added

import sys to the corresponding py file
import os
current_dir = os.path.dirname(os.path.abspath(file))
sys.path.append(current_dir)

Solution: NameError: name 'xxx' is not defined after recompilation
The suspect is from xxx import *, which is caused by mutual import, as shown in the figure, all.py files are custom.

Image Image Image Image Image
@y1y2 y1y2 changed the title ModuleNotFoundError: No module named 'xxx' and NameError: name 'TraceContext' is not defined ModuleNotFoundError: No module named 'xxx' and NameError: name 'xxx' is not defined Jan 15, 2025
@msimacek
Copy link
Contributor

I don't understand your file layout, what is xxx? Where is it imported?
Does your python code work under CPython?

There is already a module named java in the standard library, it could be causing problems. Please rename the module or put all your modules into a package to namespace it.

@y1y2
Copy link
Author

y1y2 commented Jan 24, 2025

I tried to modify the file name of java.py for java execution
”context.eval(source)“
No problem, but I use
“ctx.getBindings(mainScriptType).getMember("a").execute()”
Call a function a() in a.py, which calls the b() method in another b.py file with a
“NameError: name 'xxx' is not defined”,
xxx is a reference to a function under b(),
if I move b() to the a.y file, there is no problem, this has been troubling for a long time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants