imagej / pyimagej

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

ImageJ initialisation taking forever? #99

Closed u2056710 closed 1 year ago

u2056710 commented 3 years ago

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.

elevans commented 3 years 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:

StudDavid commented 3 years ago

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.

u2056710 commented 3 years ago

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

StudDavid commented 3 years ago

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.

StudDavid commented 3 years ago

After deleting the FilamentDetector-1.0.0.jar from the /jars subfolder, it works also with the locally installed Fiji version.

jankaWIS commented 3 years ago

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.

ctrueden commented 3 years ago

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 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:

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.

BjornFJohansson commented 3 years ago

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
mamba list output: ``` _libgcc_mutex 0.1 conda_forge conda-forge _openmp_mutex 4.5 1_gnu conda-forge alabaster 0.7.12 py_0 conda-forge alsa-lib 1.2.3 h516909a_0 conda-forge appdirs 1.4.4 pyh9f0ad1d_0 conda-forge argh 0.26.2 pyh9f0ad1d_1002 conda-forge argon2-cffi 20.1.0 py38h1e0a361_1 conda-forge astroid 2.4.2 py38h32f6830_0 conda-forge astropy 4.1 py38h0b5ebd8_2 conda-forge atk 2.36.0 ha770c72_4 conda-forge atk-1.0 2.36.0 h516909a_2 conda-forge atomicwrites 1.4.0 pyh9f0ad1d_0 conda-forge attrs 20.2.0 pyh9f0ad1d_0 conda-forge autopep8 1.5.4 pyh9f0ad1d_0 conda-forge babel 2.8.0 py_0 conda-forge backcall 0.2.0 pyh9f0ad1d_0 conda-forge backports 1.0 py_2 conda-forge backports.functools_lru_cache 1.6.1 py_0 conda-forge bandwagon 0.3.1 pypi_0 pypi beautifulsoup4 4.9.1 py_1 conda-forge bio-info-questions 0.0.8 dev_0 biopython 1.78 py38h1e0a361_0 conda-forge black 20.8b1 pypi_0 pypi bleach 3.2.1 pyh9f0ad1d_0 conda-forge blinker 1.4 py_1 conda-forge boost 1.74.0 py38hf6732f7_2 conda-forge boost-cpp 1.74.0 h9359b55_0 conda-forge brotlipy 0.7.0 py38h1e0a361_1000 conda-forge bzip2 1.0.8 h516909a_3 conda-forge c-ares 1.16.1 h516909a_3 conda-forge ca-certificates 2021.1.19 h06a4308_0 defaults cachetools 4.1.1 py_0 conda-forge cai 1.0.3 pypi_0 pypi cairo 1.16.0 h3fc0475_1005 conda-forge certifi 2020.12.5 py38h578d9bd_1 conda-forge cffi 1.14.3 py38h5bae8af_0 conda-forge cfgv 3.2.0 py_0 conda-forge chaospy 3.3.8 py_0 conda-forge chardet 3.0.4 py38h32f6830_1007 conda-forge click 7.1.2 pyh9f0ad1d_0 conda-forge cloudpickle 1.6.0 py_0 conda-forge cmarkgfm 0.4.2 py38h516909a_2 conda-forge colorama 0.4.3 py_0 conda-forge conda 4.9.2 py38h578d9bd_0 conda-forge conda-package-handling 1.7.0 py38h1e0a361_5 conda-forge coverage 5.2.1 py38h1e0a361_0 conda-forge cryptography 3.1 py38h766eaa4_0 conda-forge curl 7.71.1 he644dc0_6 conda-forge cycler 0.10.0 py_2 conda-forge cython 0.29.21 py38h950e882_0 conda-forge dateparser 0.7.6 pypi_0 pypi dbus 1.13.6 he372182_0 conda-forge decorator 4.4.2 py_0 conda-forge defusedxml 0.6.0 py_0 conda-forge diff-match-patch 20200713 pyh9f0ad1d_0 conda-forge distlib 0.3.1 pyh9f0ad1d_0 conda-forge dna-features-viewer 3.0.1 pypi_0 pypi docopt 0.6.2 py_1 conda-forge docopt-ng 0.7.2 pypi_0 pypi docpie 0.4.3 pypi_0 pypi docutils 0.16 py38h32f6830_1 conda-forge dropbox 10.1.1 pyh9f0ad1d_0 conda-forge editdistance 0.5.3 py38h950e882_2 conda-forge entrypoints 0.3 py38h32f6830_1001 conda-forge et_xmlfile 1.0.1 py_1001 conda-forge expat 2.2.9 he1b5a44_2 conda-forge ezodf 0.3.2 py_2 conda-forge fastcache 1.1.0 py38h1e0a361_1 conda-forge ffmpeg 4.3.1 h167e202_0 conda-forge filelock 3.0.12 pyh9f0ad1d_0 conda-forge flake8 3.8.3 py_1 conda-forge fontconfig 2.13.1 h1056068_1002 conda-forge freetype 2.10.2 he06d7ca_0 conda-forge fribidi 1.0.10 h36c2ea0_0 conda-forge future 0.18.2 py38h32f6830_1 conda-forge fuzzywuzzy 0.17.0 py_0 conda-forge gdk-pixbuf 2.38.2 h3f25603_6 conda-forge gettext 0.19.8.1 hc5be6a0_1002 conda-forge giflib 5.2.1 h516909a_2 conda-forge gitdb 4.0.5 py_0 conda-forge gitpython 3.1.11 py_0 conda-forge glib 2.66.0 h0dae87d_0 conda-forge gmp 6.2.0 he1b5a44_2 conda-forge gmpy2 2.1.0b1 py38h04dde30_0 conda-forge gnutls 3.6.13 h79a8f9a_0 conda-forge gobject-introspection 1.66.1 py38h03d966d_1 conda-forge google-api-core 1.23.0 pyh9f0ad1d_0 conda-forge google-api-python-client 1.12.8 pyhd3deb0d_0 conda-forge google-auth 1.21.1 py_0 conda-forge google-auth-httplib2 0.0.3 py_3 conda-forge google-auth-oauthlib 0.4.1 py_2 conda-forge googleapis-common-protos 1.51.0 py38h32f6830_2 conda-forge graphite2 1.3.13 he1b5a44_1001 conda-forge gspread 3.6.0 pypi_0 pypi gst-plugins-base 1.14.5 h0935bb2_2 conda-forge gstreamer 1.14.5 h36ae1b5_2 conda-forge gtk2 2.24.32 h194ddfc_3 conda-forge harfbuzz 2.7.2 hee91db6_0 conda-forge html2text 2020.1.16 pypi_0 pypi httplib2 0.18.1 pyh9f0ad1d_0 conda-forge httpretty 1.0.2 py_0 conda-forge icu 67.1 he1b5a44_0 conda-forge identify 1.5.10 pyhd3deb0d_0 conda-forge idna 2.10 pyh9f0ad1d_0 conda-forge imagesize 1.2.0 py_0 conda-forge imglyb 1.0.0 pyh050c7b8_0 conda-forge importlib-metadata 1.7.0 py38h32f6830_0 conda-forge importlib_metadata 1.7.0 0 conda-forge iniconfig 1.0.1 pyh9f0ad1d_0 conda-forge intervaltree 3.0.2 py_0 conda-forge ipycache 0.1.5 pyh95af2a2_0 conda-forge ipycanvas 0.5.0 pyh9f0ad1d_0 conda-forge ipykernel 5.3.4 py38h23f93f0_0 conda-forge ipynb 0.5.1 pypi_0 pypi ipython 7.18.1 py38h1cdfbd6_0 conda-forge ipython_genutils 0.2.0 py_1 conda-forge ipywidgets 7.5.1 pyh9f0ad1d_1 conda-forge isort 5.5.0 py38h32f6830_0 conda-forge jdcal 1.4.1 py_0 conda-forge jedi 0.17.1 py38h32f6830_0 conda-forge jeepney 0.4.3 py_0 conda-forge jgo 1.0.0 pyhd8ed1ab_0 conda-forge jinja2 2.11.2 pyh9f0ad1d_0 conda-forge joblib 0.17.0 py_0 conda-forge jpeg 9d h516909a_0 conda-forge jpype1 1.2.1 py38h1fd1430_0 conda-forge jsonschema 3.2.0 py38h32f6830_1 conda-forge jupyter 1.0.0 py_2 conda-forge jupyter_client 6.1.7 py_0 conda-forge jupyter_console 6.2.0 py_0 conda-forge jupyter_core 4.6.3 py38h32f6830_1 conda-forge jupytext 1.6.0 pyh9f0ad1d_0 conda-forge keyring 21.4.0 py38h32f6830_1 conda-forge kiwisolver 1.2.0 py38hbf85e49_0 conda-forge krb5 1.17.1 hfafb76e_3 conda-forge lame 3.100 h14c3975_1001 conda-forge lazy-object-proxy 1.4.3 py38h1e0a361_2 conda-forge lcms2 2.11 hbd6801e_0 conda-forge ld_impl_linux-64 2.35 h769bd43_9 conda-forge libarchive 3.3.3 hddc7a2b_1008 conda-forge libblas 3.8.0 17_openblas conda-forge libcblas 3.8.0 17_openblas conda-forge libclang 10.0.1 default_hde54327_1 conda-forge libcurl 7.71.1 hcdd3856_6 conda-forge libedit 3.1.20191231 he28a2e2_2 conda-forge libev 4.33 h516909a_1 conda-forge libevent 2.1.10 hcdb4288_2 conda-forge libffi 3.2.1 he1b5a44_1007 conda-forge libgcc 7.2.0 h69d50b8_2 conda-forge libgcc-ng 9.3.0 h24d8f2e_16 conda-forge libgfortran-ng 7.5.0 hdf63c60_16 conda-forge libglu 9.0.0 he1b5a44_1001 conda-forge libgomp 9.3.0 h24d8f2e_16 conda-forge libiconv 1.16 h516909a_0 conda-forge liblapack 3.8.0 17_openblas conda-forge libllvm10 10.0.1 he513fc3_3 conda-forge libnghttp2 1.41.0 h8cfc5f6_2 conda-forge libopenblas 0.3.10 pthreads_hb3c22a3_4 conda-forge libopenssl-static 1.1.1g h516909a_1 conda-forge libpng 1.6.37 hed695b0_2 conda-forge libpq 12.3 h5513abc_0 conda-forge libprotobuf 3.13.0 h8b12597_0 conda-forge libsodium 1.0.18 h516909a_0 conda-forge libsolv 0.7.16 h8b12597_0 conda-forge libspatialindex 1.9.3 he1b5a44_3 conda-forge libssh2 1.9.0 hab1572f_5 conda-forge libstdcxx-ng 9.3.0 hdf63c60_16 conda-forge libtiff 4.1.0 hc7e4089_6 conda-forge libuuid 2.32.1 h14c3975_1000 conda-forge libwebp-base 1.1.0 h516909a_3 conda-forge libxcb 1.13 h14c3975_1002 conda-forge libxkbcommon 0.10.0 he1b5a44_0 conda-forge libxml2 2.9.10 h68273f3_2 conda-forge libxslt 1.1.33 h572872d_1 conda-forge lxml 4.5.0 py38hefd8a0e_0 defaults lz4-c 1.9.2 he1b5a44_3 conda-forge lzo 2.10 h516909a_1000 conda-forge markdown-it-py 0.5.4 py_0 conda-forge markupsafe 1.1.1 py38h1e0a361_1 conda-forge matplotlib 3.3.1 1 conda-forge matplotlib-base 3.3.1 py38h91b0d89_0 conda-forge maven 3.6.0 0 conda-forge mccabe 0.6.1 py_1 conda-forge mistune 0.8.4 py38h1e0a361_1001 conda-forge more-itertools 5.0.0 pypi_0 pypi mpc 1.1.0 h04dde30_1009 conda-forge mpfr 4.0.2 he80fd80_1 conda-forge mpldatacursor 0.7.1 py_0 BjornFJohansson mpmath 1.1.0 py_0 conda-forge msgpack-python 1.0.0 py38hbf85e49_1 conda-forge multidict 5.0.2 py38h27cfd23_2 defaults mypy-extensions 0.4.3 pypi_0 pypi mysql-common 8.0.21 2 conda-forge mysql-libs 8.0.21 hf3661c5_2 conda-forge natsort 7.0.1 py_0 conda-forge nb_conda_kernels 2.2.4 py38h32f6830_0 conda-forge nbconvert 5.6.1 py38_0 conda-forge nbdime 2.1.0 py_0 conda-forge nbformat 5.0.7 py_0 conda-forge nbval 0.9.6 pyh9f0ad1d_0 conda-forge ncurses 6.2 he1b5a44_1 conda-forge nettle 3.4.1 h1bed415_1002 conda-forge networkx 2.5 py_0 conda-forge nodeenv 1.5.0 pyh9f0ad1d_0 conda-forge nodejs 6.13.1 0 conda-forge nose 1.3.7 py38h32f6830_1004 conda-forge notebook 6.1.4 py38h32f6830_0 conda-forge nspr 4.28 he1b5a44_0 conda-forge nss 3.57 he751ad9_0 conda-forge numpoly 1.1.0 pyhd8ed1ab_0 conda-forge numpy 1.19.1 py38hbc27379_2 conda-forge numpydoc 1.1.0 pyh9f0ad1d_0 conda-forge oauth2client 4.1.3 py_0 conda-forge oauthlib 3.0.1 py_0 conda-forge olefile 0.46 py_0 conda-forge openh264 2.1.1 h8b12597_0 conda-forge openjdk 8.0.265 h516909a_0 conda-forge openjpeg 2.3.1 h981e76c_3 conda-forge openpyxl 3.0.3 py_0 conda-forge openssl 1.1.1j h7f98852_0 conda-forge p7zip 16.02 he1b5a44_1000 conda-forge packaging 20.4 pyh9f0ad1d_0 conda-forge pandas 1.1.2 py38h950e882_0 conda-forge pandoc 2.10.1 h516909a_0 conda-forge pandocfilters 1.4.2 py_1 conda-forge pango 1.42.4 h7062337_4 conda-forge parso 0.7.0 pyh9f0ad1d_0 conda-forge pathlib2 2.3.5 py38h578d9bd_2 conda-forge pathspec 0.8.0 pypi_0 pypi pathtools 0.1.2 py_1 conda-forge patool 1.12 py38h32f6830_1001 conda-forge pcre 8.44 he1b5a44_0 conda-forge pdfminer.six 20201018 py_2 conda-forge perl 5.26.2 h516909a_1006 conda-forge pexpect 4.8.0 py38h32f6830_1 conda-forge pickleshare 0.7.5 py38h32f6830_1001 conda-forge pillow 8.0.1 py38h9776b28_0 conda-forge pint 0.15 py_0 conda-forge pip 21.0.1 pyhd8ed1ab_0 conda-forge pixman 0.38.0 h516909a_1003 conda-forge pkginfo 1.5.0.1 py_0 conda-forge pluggy 0.13.1 py38h924ce5b_3 conda-forge poppler 0.65.0 h14e79db_0 conda-forge poppler-data 0.4.9 1 conda-forge pre-commit 2.7.1 py38h32f6830_0 conda-forge prettytable 0.7.2 py_3 conda-forge prometheus_client 0.8.0 pyh9f0ad1d_0 conda-forge prompt-toolkit 3.0.7 py_0 conda-forge prompt_toolkit 3.0.7 0 conda-forge protobuf 3.13.0 py38h950e882_0 conda-forge psutil 5.7.2 py38h1e0a361_0 conda-forge pthread-stubs 0.4 h14c3975_1001 conda-forge ptyprocess 0.6.0 py_1001 conda-forge py 1.10.0 pyhd3deb0d_0 conda-forge pyasn1 0.4.8 py_0 conda-forge pyasn1-modules 0.2.7 py_0 conda-forge pycairo 1.20.0 py38h323dad1_1 conda-forge pycodestyle 2.6.0 pyh9f0ad1d_0 conda-forge pycosat 0.6.3 py38h1e0a361_1004 conda-forge pycparser 2.20 pyh9f0ad1d_2 conda-forge pydna 4.0.0a4.dev2+g1830175dd0 dev_0 pydocstyle 5.1.1 py_0 conda-forge pydrive2 1.7.0 pyhd3deb0d_0 conda-forge pyenchant 3.2.0 pypi_0 pypi pyfiglet 0.8.post1 py_0 conda-forge pyflakes 2.2.0 pyh9f0ad1d_0 conda-forge pygal 2.4.0 py_0 conda-forge pygenome 4.0.0a7 dev_0 pygments 2.7.1 py_0 conda-forge pyimagej 1.0.0 py38h578d9bd_0 conda-forge pyjwt 1.7.1 py_0 conda-forge pylint 2.6.0 py38h32f6830_0 conda-forge pyopenssl 19.1.0 py_1 conda-forge pyparsing 2.4.7 pyh9f0ad1d_0 conda-forge pypubsub 4.0.3 py_0 conda-forge pyqt 5.12.3 py38ha8c2ead_3 conda-forge pyqt5-sip 4.19.18 pypi_0 pypi pyqtchart 5.12 pypi_0 pypi pyqtwebengine 5.12.1 pypi_0 pypi pyrsistent 0.17.3 py38h1e0a361_0 conda-forge pysces 0.9.8 py38h6ebd63d_1 pysces pysocks 1.7.1 py38h32f6830_1 conda-forge pytest 6.2.1 py38h578d9bd_0 conda-forge pytest-cov 2.10.1 pyh9f0ad1d_0 conda-forge pytest-doctestplus 0.8.0 py_0 conda-forge pytest-mock 3.3.1 py_0 conda-forge pytest-runner 5.2 py_0 conda-forge python 3.8.5 h1103e12_7_cpython conda-forge python-dateutil 2.8.1 py_0 conda-forge python-jsonrpc-server 0.4.0 pyh9f0ad1d_0 conda-forge python-language-server 0.35.1 py_0 conda-forge python-levenshtein 0.12.0 py38h1e0a361_1001 conda-forge python_abi 3.8 1_cp38 conda-forge pytimeparse 1.1.8 py_0 conda-forge pytz 2020.1 pyh9f0ad1d_0 conda-forge pyxdg 0.26 py_0 conda-forge pyyaml 5.3.1 py38h1e0a361_0 conda-forge pyzmq 19.0.2 py38ha71036d_0 conda-forge qdarkstyle 2.8.1 pyh9f0ad1d_1 conda-forge qt 5.12.9 h1f2b2cb_0 conda-forge qtawesome 0.7.2 pyh9f0ad1d_0 conda-forge qtconsole 4.7.7 pyh9f0ad1d_0 conda-forge qtpy 1.9.0 py_0 conda-forge rdkit 2020.03.6 py38he572eef_1 conda-forge readline 8.0 he28a2e2_2 conda-forge readme_renderer 24.0 pyh9f0ad1d_0 conda-forge regex 2020.6.8 pypi_0 pypi reportlab 3.5.51 py38he152a6b_0 conda-forge reproc 14.2.1 h36c2ea0_0 conda-forge reproc-cpp 14.2.1 h58526e2_0 conda-forge requests 2.24.0 pyh9f0ad1d_0 conda-forge requests-mock 1.8.0 pyh9f0ad1d_0 conda-forge requests-oauthlib 1.3.0 pyh9f0ad1d_0 conda-forge requests-toolbelt 0.9.1 py_0 conda-forge rfc3986 1.4.0 pyh9f0ad1d_0 conda-forge rope 0.17.0 pyh9f0ad1d_0 conda-forge rsa 4.6 pyh9f0ad1d_0 conda-forge rtree 0.9.4 py38h08f867b_1 conda-forge ruamel_yaml 0.15.80 py38h1e0a361_1002 conda-forge scikit-learn 0.23.2 py38h5d63f67_3 conda-forge scipy 1.5.2 py38h8c5af15_0 conda-forge scyjava 1.1.0 pyhd8ed1ab_0 conda-forge secretstorage 3.1.2 py38h32f6830_1 conda-forge seguid-calculator 1.1.0 dev_0 send2trash 1.5.0 py38_0 defaults setuptools 52.0.0 py38h06a4308_0 defaults setuptools-scm 4.1.2 pyh9f0ad1d_0 conda-forge setuptools_scm 4.1.2 0 conda-forge simplejson 3.17.2 py38h1e0a361_0 conda-forge six 1.15.0 pyh9f0ad1d_0 conda-forge smmap 3.0.4 pyh9f0ad1d_0 conda-forge snapgene-reader 0.1.18 pypi_0 pypi snowballstemmer 2.0.0 py_0 conda-forge sortedcontainers 2.2.2 pyh9f0ad1d_0 conda-forge soupsieve 2.0.1 py_1 conda-forge sphinx 3.2.1 py_0 conda-forge sphinxcontrib-applehelp 1.0.2 py_0 conda-forge sphinxcontrib-devhelp 1.0.2 py_0 conda-forge sphinxcontrib-htmlhelp 1.0.3 py_0 conda-forge sphinxcontrib-jsmath 1.0.1 py_0 conda-forge sphinxcontrib-qthelp 1.0.3 py_0 conda-forge sphinxcontrib-serializinghtml 1.1.4 py_0 conda-forge spyder-kernels 1.10.1 py38h578d9bd_0 conda-forge sqlite 3.33.0 h4cf870e_0 conda-forge stapler 1.0.0 pypi_0 pypi style 1.1.0 pypi_0 pypi sympy 1.6.2 py38h32f6830_0 conda-forge termcolor 1.1.0 py38_1 defaults terminado 0.8.3 py38h32f6830_1 conda-forge testpath 0.4.4 py_0 conda-forge texlive-core 20180414 pl526hc0a3334_3 conda-forge threadpoolctl 2.1.0 pyh5ca1d4c_0 conda-forge tk 8.6.10 hed695b0_0 conda-forge toml 0.10.1 pyh9f0ad1d_0 conda-forge tornado 6.0.4 py38h1e0a361_1 conda-forge tqdm 4.54.0 pyhd8ed1ab_0 conda-forge traitlets 4.3.3 py38h32f6830_1 conda-forge twine 3.2.0 py38h32f6830_0 conda-forge typed-ast 1.4.1 pypi_0 pypi typing-extensions 3.7.4.3 pypi_0 pypi tzlocal 2.1 pypi_0 pypi ujson 3.2.0 py38h950e882_0 conda-forge update 0.0.1 pypi_0 pypi uritemplate 3.0.1 py_0 conda-forge urllib3 1.25.10 py_0 conda-forge virtualenv 20.2.1 py38h578d9bd_0 conda-forge watchdog 0.10.3 py38h32f6830_1 conda-forge wcwidth 0.2.5 pyh9f0ad1d_1 conda-forge webencodings 0.5.1 py_1 conda-forge wheel 0.35.1 pyh9f0ad1d_0 conda-forge widgetsnbextension 3.5.1 py38h32f6830_1 conda-forge wikidpadmp 2.4a1.dev2 dev_0 wkhtmltopdf 0.12.4 1 conda-forge wrapt 1.11.2 py38h1e0a361_0 conda-forge wurlitzer 2.0.0 py38h32f6830_1 conda-forge wxpython 4.1.0 py38h725c64c_0 conda-forge x264 1!152.20180806 h14c3975_0 conda-forge xarray 0.16.2 pyhd8ed1ab_0 conda-forge xmltodict 0.12.0 pypi_0 pypi xorg-fixesproto 5.0 h14c3975_1002 conda-forge xorg-inputproto 2.3.2 h14c3975_1002 conda-forge xorg-kbproto 1.0.7 h14c3975_1002 conda-forge xorg-libice 1.0.10 h516909a_0 conda-forge xorg-libsm 1.2.3 h84519dc_1000 conda-forge xorg-libx11 1.6.12 h516909a_0 conda-forge xorg-libxau 1.0.9 h14c3975_0 conda-forge xorg-libxdmcp 1.1.3 h516909a_0 conda-forge xorg-libxext 1.3.4 h516909a_0 conda-forge xorg-libxfixes 5.0.3 h516909a_1004 conda-forge xorg-libxi 1.7.10 h516909a_0 conda-forge xorg-libxrender 0.9.10 h516909a_1002 conda-forge xorg-libxtst 1.2.3 h516909a_1002 conda-forge xorg-recordproto 1.14.2 h516909a_1002 conda-forge xorg-renderproto 0.11.1 h14c3975_1002 conda-forge xorg-xextproto 7.3.0 h14c3975_1002 conda-forge xorg-xproto 7.0.31 h14c3975_1007 conda-forge xz 5.2.5 h516909a_1 conda-forge yaml 0.2.5 h516909a_0 conda-forge yapf 0.30.0 pyh9f0ad1d_0 conda-forge yarl 1.5.1 py38h1e0a361_0 conda-forge youtube-dl 2020.11.1.1 pypi_0 pypi zeromq 4.3.2 he1b5a44_3 conda-forge zipp 3.1.0 py_0 conda-forge zlib 1.2.11 h516909a_1009 conda-forge zstd 1.4.5 h6597ccf_2 conda-forge ```
jankaWIS commented 3 years ago

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 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. 😄

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?

ctrueden commented 2 years ago

@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.

jan-glx commented 2 years ago

*JAVA_TOOL_OPTIONS not JAVA_FLAGS

ctrueden commented 2 years ago

Since writing the above reply, I have now enhanced the Troubleshooting guide in the documentation to talk about ways to control the proxy settings:

https://github.com/imagej/pyimagej/blob/718097feec82fb2353168dbbeb26afad187206a7/doc/Troubleshooting.md#common-errors

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).

ctrueden commented 1 year ago

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!