imagej / pyimagej

Use ImageJ from Python
https://pyimagej.readthedocs.io/
Other
473 stars 82 forks source link

JVM required files #311

Closed CanYing0913 closed 1 month ago

CanYing0913 commented 3 months ago

What are the files required to start the JVM in jpype and use by pyimagej? I have a program and eventually I need to freeze it to executables (i.e., *.exe on Windows) using cx_freeze. This leads to the error below:

Process Process-1:
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
  File "C:\Users\PC\mambaforge\envs\cz\lib\multiprocessing\pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "C:\Users\PC\mambaforge\envs\cz\lib\multiprocessing\pool.py", line 51, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
  File "D:\CanYing\Code\CaImAn\src\src_stabilizer.py", line 22, in run_plugin
    ij = imagej.init(str(ijp), mode='headless')
  File "C:\Users\PC\mambaforge\envs\cz\lib\site-packages\imagej_init_.py", line 1211, in init
    success = _create_jvm(ij_dir_or_version_or_endpoint, mode, add_legacy)
  File "C:\Users\PC\mambaforge\envs\cz\lib\site-packages\imagej_init_.py", line 1312, in _create_jvm
    if hasattr(sj, "jvm_version") and sj.jvm_version()[0] >= 9:
  File "C:\Users\PC\mambaforge\envs\cz\lib\site-packages\scyjava_jvm.py", line 68, in jvm_version
    default_jvm_path = jpype.getDefaultJVMPath()
  File "C:\Users\PC\mambaforge\envs\cz\lib\site-packages\jpype_jvmfinder.py", line 74, in getDefaultJVMPath
    return finder.get_jvm_path()
  File "C:\Users\PC\mambaforge\envs\cz\lib\site-packages\jpype_jvmfinder.py", line 212, in get_jvm_path
    raise JVMNotFoundException("No JVM shared library file ({0}) "
jpype._jvmfinder.JVMNotFoundException: No JVM shared library file (jvm.dll) found. Try setting up the JAVA_HOME environment variable properly.

Note that the error was from my frozen application, (i.e. running my program from source code using cz mamba environment works perfectly). So, I begin to think if I can bring all JVM-related files with my application, (as if what JAVA_HOME points to in a mamba environment), so that I can directly point my JAVA_HOME environment variable to it, without worrying about it.

ctrueden commented 1 month ago

@CanYing0913 Sorry for the slow reply. And unfortunately, I don't know exactly which files you are going to need to include in the freeze. You are doing something no one else is doing, so you will need to experiment to figure out what works. If you come up with a recipe, you are welcome to contribute it to the PyImageJ documentation and/or DevOps pipeline as an option for others.