Python modules using Jython

70 Views Asked by At

I am trying to make some utils for a Python script that run using Jython 2.7.0 (I could update if needed)

My current problem is pretty simple, i can't import/use my module For a bit of context, my python script is run by the Jython-standalone jar, as a Minecraft mod, so its kinda annoying to even get it to detect the modules

When I first tried to import my module, by putting them all in the same folder, I couldn't import them, so I did:

import sys

sys.path.append("C:\Users\<myUser>\Desktop\BotUHC+")

import UHCGame #My Module i want to import

def interact(e):
    UHCGame.setupBaseGame(e)

Now, my module doesn't send back any "ImportError module not found", but I can't call that function from UHCGame, because i get the error:

javax.script.ScriptException: AttributeError: 'module' object has no attribute 'setupBaseGame' in <script> at line number 9

Despite it being present in the UHCGame.py file, even VSCode auto completion can detect it.

I wandered inside Jython's docs, and found out that it needs to compile some class before importing them, and for some reason, mine wasn't compiled, so i manually compiled it, and still got the same result.

For more info:

  • The script that is run "TestFile.py", is in -> .minecraft/saves/world/customnpc/script/python/
  • The module is in "C:\Users<myUser>\Desktop\BotUHC+", as for the compiled version of it
0

There are 0 best solutions below