MicroRTS-Py icon indicating copy to clipboard operation
MicroRTS-Py copied to clipboard

Java Import Error when running hello_world.py

Open Aniveal opened this issue 1 year ago • 5 comments

Installation ran without issues. However, when I try to run any python script, I get the following error:

Error

I am pretty sure that I installed all dependencies properly.

Thanks for the help

Aniveal avatar Apr 12 '24 09:04 Aniveal

I'm a bit surprised you don't have a huge list of output lines after it says building .../microrts.jar..., listing all the class files it's compiling and including. I always get that, though I never build on Windows, only on Linux (or, actually: Windows Subsystem for Linux). Not sure if that matters.

What does the microrts.jar file you get at the filepath it mentions look like? Is there one at all? How big is it? Can you open it as an archive and take a screenshot of what's in there?

DennisSoemers avatar Apr 12 '24 11:04 DennisSoemers

Thanks for the reply!

There is no microrts.jar file at that location or anywhere else, so I think it just fails building. Could it be that the filepaths are just wrong because of "/" instead of "\"?

I'll try WSL and see if it works.

Aniveal avatar Apr 12 '24 13:04 Aniveal

Maybe, not sure. Or maybe just something else about the build script is Linux-specific. Personally I do indeed use WSL though, and would recommend that anyway. Don't know if it should matter for the build script (maybe it does), but regardless of that, I would also recommend it because in my experience, frameworks like PyTorch are also often a pain in Windows.

DennisSoemers avatar Apr 12 '24 13:04 DennisSoemers

I am also running into this issue specifically after trying to get this to run on my laptop as well after successfully getting it to run on my PC. I am on Windows

`$ python hello_world.py removing C:\Users\40179558\MicroRTS-py\gym_microrts\microrts/microrts.jar... building C:\Users\40179558\MicroRTS-py\gym_microrts\microrts/microrts.jar... C:\Users\40179558\MicroRTS-py Traceback (most recent call last): File "org.jpype.JPypeContext.java", line -1, in org.jpype.JPypeContext.callMethod Exception: Java Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\40179558\AppData\Local\pypoetry\Cache\virtualenvs\gym-microrts-Llpb_R3--py3.9\lib\site-packages\jpype\imports.py", line 195, in find_spec cls = _jpype._java_lang_Class.forName(name, True, _jpype.JPypeClassLoader) java.lang.java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: rts.units.UnitTypeTable

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\40179558\MicroRTS-py\hello_world.py", line 10, in envs = MicroRTSGridModeVecEnv( File "C:\Users\40179558\MicroRTS-py\gym_microrts\envs\vec_env.py", line 120, in init from rts.units import UnitTypeTable File "C:\Users\40179558\AppData\Local\pypoetry\Cache\virtualenvs\gym-microrts-Llpb_R3--py3.9\lib\site-packages\poetry_dynamic_versioning_init_.py", line 416, in alt_import module = _state.original_import_func(name, globals, locals, fromlist, level) File "C:\Users\40179558\AppData\Local\pypoetry\Cache\virtualenvs\gym-microrts-Llpb_R3--py3.9\lib\site-packages\jpype\imports.py", line 203, in find_spec raise ImportError("Failed to import '%s'" % name) from ex ImportError: Failed to import 'rts.units.UnitTypeTable'`

Rookie2907 avatar Apr 17 '24 11:04 Rookie2907

Building using WSL works for me, so I assume the problem is because of Path format and/or Windows can't run .sh out of the box (Git for Windows adds integrations that allows it. These integrations might not encompass cmd.exe by default)

You may still get the ImportError: Failed to import 'rts.units.UnitTypeTable error after running build.sh in WSL, though. If it's the same issue I was having, your Java version doesn't match. If this is the case, change line 8 in build.sh to: javac -d "./build" -cp "./lib/*" --release 8 -sourcepath "./src" $(find ./src/* | grep .java) and rerun build.sh. You should probably also set autobuild=False in the env, but that might not be necessary if you can't build with Windows.

I noticed that some of the build instructions on the MicroRTS page don't seem to be complete for Windows. I had to do a few steps in WSL because of that.

dmosher42 avatar Jul 31 '24 02:07 dmosher42