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 3.8 cannot start JVM, when jnius_config is set. #486

Closed
Csega opened this issue Feb 11, 2020 · 12 comments
Closed

Python 3.8 cannot start JVM, when jnius_config is set. #486

Csega opened this issue Feb 11, 2020 · 12 comments
Labels

Comments

@Csega
Copy link

Csega commented Feb 11, 2020

Hi guys,

I have the following problem. I installed pyjnius (version 1.2.1) using Anaconda (with Python 3.8.1). Anaconda is really comfortable, it installs a JDK as well. As far as I'm concerned, everything needed is installed, and the environment variables are set (both JAVA_HOME is correct and jvm.dll is added to the path). And the good news is, that the

import jnius
from jnius import autoclass

snippet work flawlessly. The problem starts, when I want to set some JVM options. This code snippet does not work:

import jnius_config
jnius_config.add_options('-Xrs', '-Xmx512m')
import jnius

I get the following error message:

C:\Users\[my_username]\tools\Continuum\anaconda3\envs\EDVIS\Library
Unrecognized option:
JVM failed to start
C:\Users\[my_username]\tools\Continuum\anaconda3\envs\EDVIS\Library\jre\bin\client
C:\Users\[my_username]\tools\Continuum\anaconda3\envs\EDVIS\Library\jre\bin\server
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\[my_username]\tools\Continuum\anaconda3\envs\EDVIS\lib\site-packages\jnius\__init__.py", line 48, in <module>
    raise Exception("Unable to create jni env, no jvm dll found.")
Exception: Unable to create jni env, no jvm dll found.

I was able to find this part of code in the source, which is in the ./jnius/jnius_jvm_desktop.pxi from line 50-70. The problem is, that I can't see, what is the problem! The args variable is set, filled up with the options global variable coming from jnius_config. But I can't see, that the non-empty args variable how can cause the JVM to fail. Especially with valid switches...

Can you help me solve this?

My system is:
Windows 10 64-bit
Anaconda 3 2019.10
Python 3.8.1
Pyjnius 1.2.1
OpenJDK 11.0.1

Cheers,
Csega

@Csega
Copy link
Author

Csega commented Feb 18, 2020

Any comment on this? Nobody run in this problem so far? Not even @tshirtman ?

@cmacdonald
Copy link
Contributor

cmacdonald commented Mar 11, 2020

Does the same code work on a different Python version? The code that searches for the JDK is a bit convoluted, I had to just add print() statements to figure out where it was looking.

@Csega
Copy link
Author

Csega commented Mar 31, 2020

Hi @cmacdonald! Thanks for the answer! :) I tried the same (in the same environment) with Python 3.7.6 and it works! So it seems, that this is really an issue with Python 3.8...

@cmacdonald
Copy link
Contributor

Hmmm, I had meant to write different Java version. There can be differences in the JDK layout between versions. For Linux, setting the JAVA_HOME env var really helps.

@Csega
Copy link
Author

Csega commented Apr 3, 2020

Oh, I see. I tried it in a pure Python 3.8 environment with Java 8 on Windows 10, and the same problem occured. So I think it is something to do with Python 3.8 compatibility, but I can't put my finger on it.

@tshirtman
Copy link
Member

Hey, sorry for lack of answer, i've had to do some tricks for the windows build to work with python3.8, as they changed how the dll lookup work, i'm not sure that's 100% correct, but it worked for my tests.

i think that was it https://github.com/kivy/pyjnius/blob/master/.github/workflows/create.yml#L55 but it's been a few months.

@Csega
Copy link
Author

Csega commented Jun 22, 2020

Sorry for the late answer, I did not notice your comment so far. :(

However, now I tried the whole procedure I wrote at my first comment on this issue, and it still don't work with pyjnius 1.3.0. I looked at your file, but I don't know, how to test it for myself. Can you give me directions to it?

@cmacdonald
Copy link
Contributor

I had issues with OpenJDK on Linux, and ended up rewriting a lot of the boot code.
Are you able to try installing and compiling this branch:
https://github.com/cmacdonald/pyjnius/blob/java_home
You would need MS Visual Studio tools installed though.

@hx2A
Copy link
Member

hx2A commented Jul 15, 2020

How well does this work if you try a JDK that is not installed via Anaconda?

@chbauman
Copy link

I am experiencing the same issue, the JVM is not starting when I try to set options.

  • OS: Windows 10 64-bit
  • Python: 3.8.10
  • pyjnius: 1.3.0
  • java: openjdk version "14.0.1" 2020-04-14

Example:

jnius_config.add_options("-Xmx4096")

Output:

Unrecognized option: �
Unrecognized option: �
...
Exception: Unable to create jni env, no jvm dll found.

I am not using Anaconda.

@chbauman
Copy link

As a workaround I am setting the environment variable _JAVA_OPTIONS before running my python script. This seems to work. E.g.: (Powershell on Windows 10)

$env:_JAVA_OPTIONS = "-Xmx2000m"
python .\python_script_using_pyjnius.py

@github-actions
Copy link

👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project.
Let us know if this comment was made in error, and we'll be happy to reopen the issue.

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

No branches or pull requests

6 participants