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

Java Import Error when running hello_world.py #136

Open
Aniveal opened this issue Apr 12, 2024 · 5 comments
Open

Java Import Error when running hello_world.py #136

Aniveal opened this issue Apr 12, 2024 · 5 comments

Comments

@Aniveal
Copy link

Aniveal commented Apr 12, 2024

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

@DennisSoemers
Copy link
Collaborator

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?

@Aniveal
Copy link
Author

Aniveal commented Apr 12, 2024

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.

@DennisSoemers
Copy link
Collaborator

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.

@Rookie2907
Copy link

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'`

@dmosher42
Copy link

dmosher42 commented Jul 31, 2024

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.

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

4 participants