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

Python has problems finding the JVM? #563

Open
soilstack opened this issue Nov 23, 2024 · 12 comments
Open

Python has problems finding the JVM? #563

soilstack opened this issue Nov 23, 2024 · 12 comments

Comments

@soilstack
Copy link

Windows 10 environment.

Installed Java SE Development Kit 23.0.1

Set system environment variable JAVA_HOME = C:\Program Files\Java\jdk-23\bin
(earlier i set it to JAVA_HOME = C:\Program Files\Java\jdk-23 and it had the same problem

(base) C:\Users\chivo>conda activate adore

(adore) C:\Users\chivo>python
Python 3.11.7 | packaged by Anaconda, Inc. | (main, Dec 15 2023, 18:05:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import py5
Error occurred during initialization of VM
Could not find agent library instrument on the library path, with error: Can't find dependent libraries
Module java.instrument may be missing from runtime image.

At a dead-end here. I am trying to install py5 so that I can use it in my jupyter notebook world.

@hx2A
Copy link
Collaborator

hx2A commented Nov 23, 2024

What version of py5 have you installed here? The error message you received is unusual.

Can you try installing java with the install-jdk library mentioned on the install page and unset JAVA_HOME?

@hx2A
Copy link
Collaborator

hx2A commented Nov 23, 2024

@soilstack , we will do what we can to help you here! Thank you for your interest in py5. @villares , can you assist here? You have more experience diagnosing these problems on Windows.

@villares
Copy link
Collaborator

Hi @soilstack !

I had exactly this message recently using jpype 1.5.1 (jpype1 on PyPI) but it worked with jpype 1.5.0, can you check your jpype version? (I even opened an issue at jpype's repo that we are investigating)

As a workaround I have been using this pre-installed Python env from Thonny: https://github.com/villares/thonny-portable-with-py5/releases/download/2024-11-17/thonny-416-with-py5-windows-portable.zip
I have managed once to open a system shell form Thonny's Tools menu and then ran Jupyter Lab from it, but I haven't tried that lately.

@hx2A
Copy link
Collaborator

hx2A commented Nov 23, 2024

@villares I really hope jpype 1.5.1 doesn't have some weird problem affecting windows machines.

@soilstack , can you try this:

import jpype

jpype.startJVM()

@villares
Copy link
Collaborator

villares commented Nov 23, 2024

@villares I really hope jpype 1.5.1 doesn't have some weird problem affecting windows machines.

I have bad news... Installing py5 in a fresh env gets jpype 1.5.1, and importing it like you showed to test .startJVM() can start a Java 1.8 JVM, which it found by itself, but which doesn't help us. When I set JAVA_HOME to the JDK-17 path it fails, and so py5 fails too.
The only good news is that after downgrading jpype to 1.5.0 then everything worked.

Update: I found out and reported at the jpype issue that moving jdk-17 from inside Thonny to the default Windows Java folder seems like it helps jpype find the stuff it needs. We still have a problem with 1.5.1 failing in our "Thonny-based set up" :(

@hx2A
Copy link
Collaborator

hx2A commented Nov 23, 2024

Hmm, I am confused. Are you saying that 1.5.1 can start Java 1.8 but not Java 17?

When jdk-17 is inside Thonny, is JAVA_HOME set? jpype should be able to find Java when it is in the usual locations for that OS. It won't know to look in a Thonny folder unless the environment variable is present.

@villares
Copy link
Collaborator

Hmm, I am confused. Are you saying that 1.5.1 can start Java 1.8 but not Java 17?

Kind of.

When jdk-17 is inside Thonny, is JAVA_HOME set? jpype should be able to find Java when it is in the usual locations for that OS. It won't know to look in a Thonny folder unless the environment variable is present.

Yes, Thonny sets JAVA_HOME, that works fine on jpype 1.5.0 or, if I move the JDK out, it also works in 1.5.1.
If I don't set JAVA_HOME jpype runs by default on JRE-1.8.

@soilstack
Copy link
Author

So my fix was:

  1. uninstalled all the java stuff i installed, etc.
  2. Somehow i missed the more elaborate instructions at https://py5coding.org/content/install.html I created a new environment based on http://py5coding.org/files/install/py5_environment.yml
  3. pip install install-jdk and jdk.install('17')
  4. it still didn't work, so I had to create JAVA_HOME env var
  5. it still didn't work, so I added %JAVA_HOME% to my PATH as well
    Then it works......

@hx2A
Copy link
Collaborator

hx2A commented Nov 24, 2024

Neat. Very happy it works for you, @soilstack ! Thank you for your persistence.

Are you using jpype 1.5.1 or 1.5.0?

I didn't know that number 5 would help here. @villares and I will take note of that for the future.

@brandonhornmsdk
Copy link

I installed PY5 on 2 computers in my lab yesterday and experienced the issue described. I fixed it by setting 2 user environment variables according to the instructions at:

https://jpype.readthedocs.io/en/latest/install.html

Specifically:

"On certain systems such as Windows 2016 Server, the JDK will not load properly despite JPype properly locating the JVM library. The work around for this issue is add the JRE bin directory to the system PATH. Apparently, the shared library requires dependencies which are located in the bin directory. If a JPype fails to load despite having the correct JAVA_HOME and system architecture, it may be this issue."

The environment variables are:

  • JAVA_HOME to C:\Program Files\Java\jdk21\bin
  • Add %JAVA_HOME% to Path

A restart was required.

@hx2A
Copy link
Collaborator

hx2A commented Nov 28, 2024

I installed PY5 on 2 computers in my lab yesterday and experienced the issue described. I fixed it by setting 2 user environment variables according to the instructions at:

https://jpype.readthedocs.io/en/latest/install.html

Specifically:

"On certain systems such as Windows 2016 Server, the JDK will not load properly despite JPype properly locating the JVM library. The work around for this issue is add the JRE bin directory to the system PATH. Apparently, the shared library requires dependencies which are located in the bin directory. If a JPype fails to load despite having the correct JAVA_HOME and system architecture, it may be this issue."

The environment variables are:

* JAVA_HOME to C:\Program Files\Java\jdk21\bin

* Add %JAVA_HOME% to Path

Excellent, thank you @brandonhornmsdk for your investigations here. This seems to be related to the comment on a jpype issue thread that also says to add JAVA_HOME to the path. When they fix that bug, I think this issue with py5 will be resolved?

@villares
Copy link
Collaborator

villares commented Dec 3, 2024

Excellent, thank you @brandonhornmsdk for your investigations here. This seems to be related to the comment on a jpype issue thread that also says to add JAVA_HOME to the path. When they fix that bug, I think this issue with py5 will be resolved?

Thank you very much @brandonhornmsdk, I'm also grateful that many (super nice) jpype people are working on it. Let's hope this will soon all be resolved.

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