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

Improve Jupyter Dynamic Install instructions #317

Merged
merged 2 commits into from
Oct 25, 2024
Merged

Conversation

gselzer
Copy link
Contributor

@gselzer gselzer commented Oct 24, 2024

This commit makes a few changes:

  • Uses "%mamba" over "!mamba" - has support for micromamba
  • Adds "-c conda-forge" - I found this necessary, at least for micromamba
  • Adds prefix delimiter manipulation to account for Windows paths

@elevans can you test this out on some other platforms and make sure this works?

This commit makes a few changes:
* Uses "%mamba" over "!mamba" - has support for micromamba
* Adds "-c conda-forge" - I found this necessary, at least for
  micromamba
* Adds prefix delimiter manipulation to account for Windows paths
@gselzer gselzer added the bug Something isn't working label Oct 24, 2024
@gselzer gselzer requested a review from elevans October 24, 2024 14:43
@gselzer
Copy link
Contributor Author

gselzer commented Oct 24, 2024

This might be a different issue, but if I write:

import sys, os
prefix = sys.prefix.replace("\\", "/") # Handle Windows Paths
%mamba install --yes --prefix {prefix} -c conda-forge pyimagej openjdk=11
os.environ['JAVA_HOME'] = os.sep.join(sys.executable.split(os.sep)[:-2] + ['jre'])

and then put in a separate cell:

import imagej
ij = imagej.init()

I get the following exception:

---------------------------------------------------------------------------
JVMNotFoundException                      Traceback (most recent call last)
Cell In[3], line 1
----> 1 ij = imagej.init()

File ~\micromamba\envs\tmp\Lib\site-packages\imagej\__init__.py:1211, in init(ij_dir_or_version_or_endpoint, mode, add_legacy, headless)
   1208     raise EnvironmentError("Sorry, the interactive mode is not available on macOS.")
   1210 if not sj.jvm_started():
-> 1211     success = _create_jvm(ij_dir_or_version_or_endpoint, mode, add_legacy)
   1212     if not success:
   1213         raise RuntimeError("Failed to create a JVM with the requested environment.")

File ~\micromamba\envs\tmp\Lib\site-packages\imagej\__init__.py:1312, in _create_jvm(ij_dir_or_version_or_endpoint, mode, add_legacy)
   1310     sj.config.add_option("-Djava.awt.headless=true")
   1311 try:
-> 1312     if hasattr(sj, "jvm_version") and sj.jvm_version()[0] >= 9:
   1313         # Disable illegal reflection access warnings.
   1314         sj.config.add_option("--add-opens=java.base/java.lang=ALL-UNNAMED")
   1315         sj.config.add_option("--add-opens=java.base/java.util=ALL-UNNAMED")

File ~\micromamba\envs\tmp\Lib\site-packages\scyjava\_jvm.py:68, in jvm_version()
     63     return jvm_version
     65 # JPype was clueless, which means the JVM has probably not started yet.
     66 # Let's look for a java executable, and ask via 'java -version'.
---> 68 default_jvm_path = jpype.getDefaultJVMPath()
     69 if not default_jvm_path:
     70     raise RuntimeError("Cannot glean the default JVM path")

File ~\micromamba\envs\tmp\Lib\site-packages\jpype\_jvmfinder.py:74, in getDefaultJVMPath()
     72 else:
     73     finder = LinuxJVMFinder()
---> 74 return finder.get_jvm_path()

File ~\micromamba\envs\tmp\Lib\site-packages\jpype\_jvmfinder.py:212, in JVMFinder.get_jvm_path(self)
    210 if jvm_notsupport_ext is not None:
    211     raise jvm_notsupport_ext
--> 212 raise JVMNotFoundException("No JVM shared library file ({0}) "
    213                            "found. Try setting up the JAVA_HOME "
    214                            "environment variable properly."
    215                            .format(self._libfile))

JVMNotFoundException: No JVM shared library file (jvm.dll) found. Try setting up the JAVA_HOME environment variable properly.

So there's still barriers to running pyimagej in Jupyter, at least on Windows...

@elevans
Copy link
Member

elevans commented Oct 24, 2024

Thanks for improving this! I'll try this out on the mac, linux and windows machines I have here. You're on Windows 11 right?

@gselzer
Copy link
Contributor Author

gselzer commented Oct 24, 2024

Thanks for improving this! I'll try this out on the mac, linux and windows machines I have here. You're on Windows 11 right?

Yes!

@ctrueden
Copy link
Member

Is there actually a jvm.dll beneath os.sep.join(sys.executable.split(os.sep)[:-2] + ['jre'])?
Does this code work outside a Jupyter notebook?
The environment activation for openjdk from conda-forge might modify your PATH variable, meaning you might need to modify this variable also on Windows...

This commit fixes how we set the JAVA_HOME variable for PyImageJ in the
dynamic install cell. The problem was 2 fold. (1) We were missing a
leading slash and (2) did not have platform specific JVM library
locations.

We may need an additional one for macOS -- this needs further testing.
@elevans
Copy link
Member

elevans commented Oct 25, 2024

Thanks @gselzer for improving this and actually getting this to work on all platforms! Looks great to me!

@elevans elevans merged commit cf3bd1b into main Oct 25, 2024
8 checks passed
@elevans elevans deleted the jupyter-install-docs branch October 25, 2024 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants