Closed u2056710 closed 1 year ago
@u2056710 Hello!
What system are you on? I just replicated your code with a fresh download of Fiji and everything is fine on my end (Ubuntu 20.04 LTS).
Some things to try:
ij = imagej.init()
Actually I ran into the same issue, running the initialization on Win 10 64x. I tried using a fresh local version and also initializing without parsing arguments. In both cases the process takes indefinitely long (> 10 min). Any hints on what may cause this would be great.
Sorry for the delayed reply @elevans. I am working on MacOS Catalina. I have tried using the latest and it still does not load.
@StudDavid I have not been able to sort it out yet but will let you know if I do!
Best wishes
This error messages I just got could be helpful:
File "test_imagej.py", line 6, in <module> ij = imagej.init("Fiji.app", headless=False) File "C:\anaconda3\envs\pyimagej\lib\site-packages\imagej\__init__.py", line 168, in init ij = ImageJ() java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Invalid service: sc.fiji.filamentdetector.gui.GUIStatusService
It occurred, when passing the local installation folder as an argument.
But it runs successfully, when initializing without an argument.
I reinstalled Java and started the basic script from a anaconda console inside the provided anaconda environment. The sample image is shown, but still got an error message stating
log4j:WARN No appenders could be found for logger (org.bushe.swing.event.EventService). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
After deleting the FilamentDetector-1.0.0.jar
from the /jars subfolder, it works also with the locally installed Fiji version.
The same here, regardless of which of those inits I try:
import imagej
# ij = imagej.init('/Applications/Fiji.app')
# ij = imagej.init()
ij = imagej.init('sc.fiji:fiji:2.0.0-pre-10')
it takes forever to do anything and does nothing. No error message, no warning, just runs in the kernel of Jupyter notebook.
Version '1.0.0' of imagej, running Mac Big Sur 11.2.1.
I would like to make it easier to debug this sort of problem in a future version of pyimagej. For now, here is some information about the two major initialization cases:
sc.fiji:fiji
The first time you run e.g. ij = imagej.init('sc.fiji:fiji:2.1.1')
, PyImageJ downloads Fiji in the background, which can take some time; if it hangs beyond a minute or two though, you can check whether your Maven installation was able to find the artifacts using this command in a separate terminal with your conda environment active:
mvn -B -f ~/.jgo/net.imglib2/imglib2-imglyb/1.0.0+net.imagej-imagej-legacy-RELEASE+sc.fiji-fiji-2.1.1/pom.xml dependency:resolve
The above assumes you are using Fiji at version 2.1.1, the newest usable version as of this writing. If you use a different version, the string above will need to be tweaked accordingly.
Alternately, it's possible to enable debug mode for jgo (the library that's doing the downloading) via:
import jgo, logging, sys
jgo.jgo._logger.addHandler(logging.StreamHandler(sys.stderr))
jgo.jgo._logger.setLevel(logging.DEBUG)
Followed by the usual import imagej
and ij = imagej.init(...)
call. You should see a lot more stuff get printed to the console, indicating what's happening with jgo. May or may not be useful, but at least it's more detail. :smile:
The fact that you are seeing hangs with both local and remote installations suggests that it's not an issue with jgo or downloading remote JAR files. With local installations, you may be bit by the problem with Fiji.app/jars/FilamentDetector-1.0.0.jar
mentioned by @StudDavid; try deleting that file before initializing from Python and see if that avoids the problem.
You can also try enabling debugging output during ImageJ/Fiji initialization as follows:
import os
os.environ['DEBUG'] = '1'
import imagej
ij = imagej.init('/Applications/Fiji.app')
And you should see a lot of debugging information get printed to the terminal about what's happening as ImageJ spins up.
@jankaWIS @u2056710 Please let us know if any of the above gives any further clues on the issues you're experiencing.
Hi, I also have this problem. I installed from conda forge as instructed from the readme of the this project.
import imageJ
seems to work, but imagej.init('sc.fiji:fiji:2.1.1')
seems to hang forever.
I did the mvn command suggested above:
(bjorn38) bjorn@bjorn-ThinkPad-T450s:~$ mvn -B -f ~/.jgo/net.imglib2/imglib2-imglyb/1.0.0+net.imagej-imagej-legacy-RELEASE+sc.fiji-fiji-2.1.1/pom.xml dependency:resolve
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for net.imglib2-BOOTSTRAPPER:imglib2-imglyb-BOOTSTRAPPER:jar:0
[WARNING] 'dependencies.dependency.version' for net.imagej:imagej-legacy:jar is either LATEST or RELEASE (both of them are being deprecated) @ line 10, column 222
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
...
[INFO]
[INFO] --- maven-dependency-plugin:2.8:resolve (default-cli) @ imglib2-imglyb-BOOTSTRAPPER ---
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-settings/2.0.9/maven-settings-2.0.9.pom
I would like to make it easier to debug this sort of problem in a future version of pyimagej. For now, here is some information about the two major initialization cases:
Using a remote endpoint such as
sc.fiji:fiji
The first time you run e.g.
ij = imagej.init('sc.fiji:fiji:2.1.1')
, PyImageJ downloads Fiji in the background, which can take some time; if it hangs beyond a minute or two though, you can check whether your Maven installation was able to find the artifacts using this command in a separate terminal with your conda environment active:mvn -B -f ~/.jgo/net.imglib2/imglib2-imglyb/1.0.0+net.imagej-imagej-legacy-RELEASE+sc.fiji-fiji-2.1.1/pom.xml dependency:resolve
The above assumes you are using Fiji at version 2.1.1, the newest usable version as of this writing. If you use a different version, the string above will need to be tweaked accordingly.
Alternately, it's possible to enable debug mode for jgo (the library that's doing the downloading) via:
import jgo, logging, sys jgo.jgo._logger.addHandler(logging.StreamHandler(sys.stderr)) jgo.jgo._logger.setLevel(logging.DEBUG)
Followed by the usual
import imagej
andij = imagej.init(...)
call. You should see a lot more stuff get printed to the console, indicating what's happening with jgo. May or may not be useful, but at least it's more detail. 😄Using a local installation
The fact that you are seeing hangs with both local and remote installations suggests that it's not an issue with jgo or downloading remote JAR files. With local installations, you may be bit by the problem with
Fiji.app/jars/FilamentDetector-1.0.0.jar
mentioned by @StudDavid; try deleting that file before initializing from Python and see if that avoids the problem.You can also try enabling debugging output during ImageJ/Fiji initialization as follows:
import os os.environ['DEBUG'] = '1' import imagej ij = imagej.init('/Applications/Fiji.app')
And you should see a lot of debugging information get printed to the terminal about what's happening as ImageJ spins up.
@jankaWIS @u2056710 Please let us know if any of the above gives any further clues on the issues you're experiencing.
I actually do not know what happened. Once I tried:
import os
os.environ['DEBUG'] = '1'
import imagej
ij = imagej.init('/Applications/Fiji.app')
it worked, now I tried again and I'm getting:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-53-c2c4f57e3a60> in <module>
2 os.environ['DEBUG'] = '1'
3 import imagej
----> 4 ij = imagej.init('/Applications/Fiji.app')
~/anaconda3/lib/python3.8/site-packages/imagej/__init__.py in init(ij_dir_or_version_or_endpoint, headless)
212 """
213 raise ImportError("Your ImageJ installation does not support IJ1. This function does not work.")
--> 214 WindowManager = JObject(_WindowManager)
215
216 class ImageJPython:
~/anaconda3/lib/python3.8/site-packages/jpype/_jobject.py in __new__(cls, *args, **kwargs)
57 if len(args) == 0:
58 return _jpype._java_lang_Object()
---> 59 return _JObjectFactory(*args, **kwargs)
60
61
~/anaconda3/lib/python3.8/site-packages/jpype/_jobject.py in _JObjectFactory(v, tp)
109 # Given a Java class
110 if isinstance(tp, _jpype._JClass):
--> 111 return tp._cast(v)
112
113 raise TypeError("Invalid type conversion to %s requested." % tp)
TypeError: Unable to cast 'type' to java type 'java.lang.Class'
And at this moment, this works:
import imagej
ij = imagej.init()
ij.getVersion() #'2.2.0/1.53c'
Update 23.2. None of the above works anymore, now I'm getting:
JVMNotFoundException Traceback (most recent call last)
<ipython-input-2-c2c4f57e3a60> in <module>
2 os.environ['DEBUG'] = '1'
3 import imagej
----> 4 ij = imagej.init('/Applications/Fiji.app')
~/anaconda3/lib/python3.8/site-packages/imagej/__init__.py in init(ij_dir_or_version_or_endpoint, headless)
160 sj.config.add_endpoints('net.imagej:imagej:' + version)
161
--> 162 sj.start_jvm()
163
164 JObjectArray = JArray(JObject)
~/anaconda3/lib/python3.8/site-packages/scyjava/__init__.py in start_jvm(options)
54
55 # initialize JPype JVM
---> 56 jpype.startJVM(*options)
57
58 # grab needed Java classes
~/anaconda3/lib/python3.8/site-packages/jpype/_core.py in startJVM(*args, **kwargs)
185 jvmpath = kwargs.pop('jvmpath')
186 if not jvmpath:
--> 187 jvmpath = getDefaultJVMPath()
188
189 # Classpath handling
~/anaconda3/lib/python3.8/site-packages/jpype/_jvmfinder.py in getDefaultJVMPath()
72 else:
73 finder = LinuxJVMFinder()
---> 74 return finder.get_jvm_path()
75
76
~/anaconda3/lib/python3.8/site-packages/jpype/_jvmfinder.py in 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."
JVMNotFoundException: No JVM shared library file (libjli.dylib) found. Try setting up the JAVA_HOME environment variable properly.
I have not changed anything in my installations except that FiJi/ImageJ got some update yesterday or the day before. Can that be a cause for the change in the error message, @ctrueden, @elevans?
@BjornFJohansson @jankaWIS Sorry for the long delay in reply. Did you manage to get it working, ever?
I wonder if these hangs are caused by firewall issues? If you still care, could you try:
import os
os.environ["JAVA_TOOL_OPTIONS"] = "-Djava.net.useSystemProxies=true"
Before running imagej.init
?
Theoretically, this will cause Maven to use your system proxy settings when querying and downloading from the remote Maven repository.
Or if you need to set proxy settings manually:
import os
mydomain = "example.com" # replace with your proxy server
myport = 8080 # replace with your proxy server's port
os.environ["JAVA_TOOL_OPTIONS"] = (
f"-Dhttp.proxyHost={mydomain}"
+ f" -Dhttp.proxyPort={myport}"
+ f" -Dhttps.proxyHost={mydomain}"
+ f" -Dhttps.proxyPort={myport}"
)
It may not be a firewall issue, though, in which case I would suggest running that mvn
invocation again from the command line. @BjornFJohansson based on your output pasted above, it looks like that command was hanging for you? If so, you could try running mvn
with the -X
flag to enable more verbose debugging output. You can also press Ctrl+\ once it hangs to get a Java stack trace, which might tell us where the code is hanging.
*JAVA_TOOL_OPTIONS
not JAVA_FLAGS
Since writing the above reply, I have now enhanced the Troubleshooting guide in the documentation to talk about ways to control the proxy settings:
I also wrote a troubleshooting analysis tool (not yet part of a PyImageJ release) which you can run like so:
python -c 'import imagej.doctor; imagej.doctor.checkup()'
Or if that doesn't work, download and run the latest version of it directly:
curl -fsLO https://raw.githubusercontent.com/imagej/pyimagej/master/src/imagej/doctor.py; python doctor.py
Right now the doctor is focused on validating your installation, but it does not yet check for proxy settings, and it does not yet warn if the Java version is too old (although it does report it).
I'm closing this due to inactivity, hoping that everyone's setups are happily working. If not, please feel welcome to reopen with details, and we will keep trying to help!
Hi - I'm trying to use ImageJ from python to run a macro, but I can't seem to initialise it, as it takes forever:
This is my code:
import imagej
print("initializing imageJ, this can take a bit of time...")
ij = imagej.init('/Applications/Fiji.app', headless=False)
print("imageJ successfully initialised.")
and my console has been on "initializing fiji, this can take a bit of time' for about an hour!
I expect that this would take some time as when I run it for the first time it will install lots of JARs, , but it has been running for hours, not sure what might be causing this/how to fix it.