spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.32k stars 1.61k forks source link

Exception in comms call get_namespace_view - Java Virtual Machine is not running #20635

Open AdamDHines opened 1 year ago

AdamDHines commented 1 year ago

Description

What steps will reproduce the problem?

I created a new environment with conda/mamba to install PyImageJ using the Anaconda Powershell prompt

conda install mamba -n base -c conda-forge
mamba create -n pyimagej -c conda-forge pyimagej openjdk
conda activate pyimagej

Switching to the newly created pyimagej environment in the Anaconda Navigator, I open Spyder 5.4.1 and run the following code to initialise the ImageJ2 Framework

import imagej
ij = imagej.init()
data = ij.io().open('/Desktop/Test/Test-1.tif')

The ij variable (a net.imagej.ImageJ object of imagej module) works fine, but trying to load a .tif image or perform any function with the ImageJ2 framework causes this Java Virtual Machine error to occur.

# Name Version Build Channel alabaster 0.7.12 pyhd3eb1b0_0 aom 3.5.0 h63175ca_0 conda-forge arrow 1.2.3 py38haa95532_1 astroid 2.14.2 py38haa95532_0 asttokens 2.0.5 pyhd3eb1b0_0 atomicwrites 1.4.0 py_0 attrs 22.1.0 py38haa95532_0 autopep8 1.6.0 pyhd3eb1b0_1 babel 2.11.0 py38haa95532_0 backcall 0.2.0 pyhd3eb1b0_0 bcrypt 3.2.0 py38h2bbff1b_1 beautifulsoup4 4.11.1 py38haa95532_0 binaryornot 0.4.4 pyhd3eb1b0_1 black 22.6.0 py38haa95532_0 bleach 4.1.0 pyhd3eb1b0_0 brotli 1.0.9 hcfcfb64_8 conda-forge brotli-bin 1.0.9 hcfcfb64_8 conda-forge brotlipy 0.7.0 py38h91455d4_1005 conda-forge bzip2 1.0.8 h8ffe710_4 conda-forge c-blosc2 2.7.1 h183a6f4_0 conda-forge ca-certificates 2023.01.10 haa95532_0 certifi 2022.12.7 py38haa95532_0 cffi 1.15.1 py38h57701bc_3 conda-forge chardet 4.0.0 py38haa95532_1003 charls 2.4.1 h1537add_0 conda-forge charset-normalizer 2.1.1 pyhd8ed1ab_0 conda-forge click 8.0.4 py38haa95532_0 cloudpickle 2.0.0 pyhd3eb1b0_0 colorama 0.4.6 py38haa95532_0 comm 0.1.2 py38haa95532_0 console_shortcut 0.1.1 4 contourpy 1.0.7 py38hb1fd069_0 conda-forge cookiecutter 1.7.3 pyhd3eb1b0_0 cryptography 39.0.1 py38h21b164f_0 cycler 0.11.0 pyhd8ed1ab_0 conda-forge dav1d 1.0.0 h8ffe710_1 conda-forge debugpy 1.5.1 py38hd77b12b_0 decorator 5.1.1 pyhd3eb1b0_0 defusedxml 0.7.1 pyhd3eb1b0_0 diff-match-patch 20200713 pyhd3eb1b0_0 dill 0.3.6 py38haa95532_0 docstring-to-markdown 0.11 py38haa95532_0 docutils 0.18.1 py38haa95532_3 entrypoints 0.4 py38haa95532_0 executing 0.8.3 pyhd3eb1b0_0 flake8 6.0.0 py38haa95532_0 fonttools 4.38.0 py38h91455d4_1 conda-forge freetype 2.12.1 ha860e81_0 giflib 5.2.1 h8d14728_2 conda-forge glib 2.69.1 h5dc1a3c_2 gst-plugins-base 1.18.5 h9e645db_0 gstreamer 1.18.5 hd78058f_0 icu 58.2 ha925a31_3 idna 3.4 pyhd8ed1ab_0 conda-forge imagesize 1.4.1 py38haa95532_0 imglyb 2.0.1 pyh8a188c0_0 conda-forge importlib-metadata 4.11.3 py38haa95532_0 importlib-resources 5.12.0 pyhd8ed1ab_0 conda-forge importlib_metadata 4.11.3 hd3eb1b0_0 importlib_resources 5.12.0 pyhd8ed1ab_0 conda-forge inflection 0.5.1 py38haa95532_0 intel-openmp 2023.0.0 h57928b3_25922 conda-forge intervaltree 3.1.0 pyhd3eb1b0_0 ipykernel 6.19.2 py38hd4e2768_0 ipython 8.10.0 py38haa95532_0 ipython_genutils 0.2.0 pyhd3eb1b0_1 isort 5.9.3 pyhd3eb1b0_0 jedi 0.18.1 py38haa95532_1 jellyfish 0.9.0 py38h2bbff1b_0 jgo 1.0.4 pyhd8ed1ab_0 conda-forge jinja2 3.1.2 py38haa95532_0 jinja2-time 0.2.0 pyhd3eb1b0_3 jpeg 9e hcfcfb64_3 conda-forge jpype1 1.4.1 py38hb1fd069_1 conda-forge jsonschema 4.17.3 py38haa95532_0 jupyter_client 7.4.9 py38haa95532_0 jupyter_core 5.2.0 py38haa95532_0 jupyterlab_pygments 0.1.2 py_0 jxrlib 1.1 h8ffe710_2 conda-forge keyring 23.4.0 py38haa95532_0 kiwisolver 1.4.4 py38hb1fd069_1 conda-forge labeling 0.1.12 pyhd8ed1ab_1 conda-forge lazy-object-proxy 1.6.0 py38h2bbff1b_0 lcms2 2.14 ha5c8aab_1 conda-forge lerc 4.0.0 h63175ca_0 conda-forge libaec 1.0.6 h63175ca_1 conda-forge libavif 0.11.1 h8f5c5bc_0 conda-forge libblas 3.9.0 16_win64_mkl conda-forge libbrotlicommon 1.0.9 hcfcfb64_8 conda-forge libbrotlidec 1.0.9 hcfcfb64_8 conda-forge libbrotlienc 1.0.9 hcfcfb64_8 conda-forge libcblas 3.9.0 16_win64_mkl conda-forge libclang 12.0.0 default_h627e005_2 libdeflate 1.17 hcfcfb64_0 conda-forge libffi 3.4.2 h8ffe710_5 conda-forge libiconv 1.17 h8ffe710_0 conda-forge liblapack 3.9.0 16_win64_mkl conda-forge libogg 1.3.5 h2bbff1b_1 libpng 1.6.39 h8cc25b3_0 libsodium 1.0.18 h62dcd97_0 libspatialindex 1.9.3 h6c2663c_0 libsqlite 3.40.0 hcfcfb64_0 conda-forge libtiff 4.5.0 h8a3f274_0 libvorbis 1.3.7 he774522_0 libwebp 1.2.4 hbc33d0d_1 libwebp-base 1.2.4 h8ffe710_0 conda-forge libxcb 1.13 hcd874cb_1004 conda-forge libxml2 2.9.14 h0ad7f3c_0 libxslt 1.1.35 h2bbff1b_0 libzopfli 1.0.3 h0e60522_0 conda-forge lxml 4.9.1 py38h1985fb9_0 lz4-c 1.9.4 hcfcfb64_0 conda-forge m2w64-gcc-libgfortran 5.3.0 6 conda-forge m2w64-gcc-libs 5.3.0 7 conda-forge m2w64-gcc-libs-core 5.3.0 7 conda-forge m2w64-gmp 6.1.0 2 conda-forge m2w64-libwinpthread-git 5.0.0.4634.697f757 2 conda-forge markupsafe 2.1.1 py38h2bbff1b_0 matplotlib-base 3.7.0 py38h528a6c7_0 conda-forge matplotlib-inline 0.1.6 py38haa95532_0 maven 3.9.0 h57928b3_0 conda-forge mccabe 0.7.0 pyhd3eb1b0_0 mistune 0.8.4 py38he774522_1000 mkl 2022.1.0 h6a75c08_874 conda-forge msys2-conda-epoch 20160418 1 conda-forge munkres 1.1.4 pyh9f0ad1d_0 conda-forge mypy_extensions 0.4.3 py38haa95532_1 nbclient 0.5.13 py38haa95532_0 nbconvert 6.5.4 py38haa95532_0 nbformat 5.7.0 py38haa95532_0 nest-asyncio 1.5.6 py38haa95532_0 numpy 1.24.2 py38h7ec9225_0 conda-forge numpydoc 1.5.0 py38haa95532_0 openjdk 17.0.3 h57928b3_5 conda-forge openssl 1.1.1t h2bbff1b_0 packaging 23.0 pyhd8ed1ab_0 conda-forge pandas 1.5.3 py38h5846ac1_0 conda-forge pandocfilters 1.5.0 pyhd3eb1b0_0 paramiko 2.8.1 pyhd3eb1b0_0 parso 0.8.3 pyhd3eb1b0_0 pathspec 0.10.3 py38haa95532_0 pcre 8.45 hd77b12b_0 pexpect 4.8.0 pyhd3eb1b0_3 pickleshare 0.7.5 pyhd3eb1b0_1003 pillow 9.4.0 py38hd77b12b_0 pip 23.0.1 pyhd8ed1ab_0 conda-forge pkgutil-resolve-name 1.3.10 py38haa95532_0 platformdirs 3.1.0 pyhd8ed1ab_0 conda-forge pluggy 1.0.0 py38haa95532_1 ply 3.11 py38_0 pooch 1.7.0 pyhd8ed1ab_0 conda-forge poyo 0.5.0 pyhd3eb1b0_0 prompt-toolkit 3.0.36 py38haa95532_0 psutil 5.9.4 py38h91455d4_0 conda-forge pthread-stubs 0.4 hcd874cb_1001 conda-forge pthreads-win32 2.9.1 hfa6e2cd_3 conda-forge ptyprocess 0.7.0 pyhd3eb1b0_2 pure_eval 0.2.2 pyhd3eb1b0_0 pycodestyle 2.10.0 py38haa95532_0 pycparser 2.21 pyhd8ed1ab_0 conda-forge pydocstyle 6.3.0 py38haa95532_0 pyflakes 3.0.1 py38haa95532_0 pygments 2.11.2 pyhd3eb1b0_0 pyimagej 1.4.0 py38haa244fe_0 conda-forge pylint 2.16.2 py38haa95532_0 pylint-venv 2.3.0 py38haa95532_0 pyls-spyder 0.4.0 pyhd3eb1b0_0 pynacl 1.5.0 py38h8cc25b3_0 pyopenssl 23.0.0 pyhd8ed1ab_0 conda-forge pyparsing 3.0.9 pyhd8ed1ab_0 conda-forge pyqt 5.15.7 py38hd77b12b_0 pyqt5-sip 12.11.0 py38hd77b12b_0 pyqtwebengine 5.15.7 py38hd77b12b_0 pyrsistent 0.18.0 py38h196d8e1_0 pysocks 1.7.1 py38haa244fe_5 conda-forge python 3.8.1 h5fd99cc_8_cpython python-dateutil 2.8.2 pyhd8ed1ab_0 conda-forge python-fastjsonschema 2.16.2 py38haa95532_0 python-lsp-black 1.2.1 py38haa95532_0 python-lsp-jsonrpc 1.0.0 pyhd3eb1b0_0 python-lsp-server 1.7.1 py38haa95532_0 python-slugify 5.0.2 pyhd3eb1b0_0 python_abi 3.8 3_cp38 conda-forge pytoolconfig 1.2.5 py38haa95532_1 pytz 2022.7.1 pyhd8ed1ab_0 conda-forge pywin32 305 py38h2bbff1b_0 pywin32-ctypes 0.2.0 py38_1000 pyyaml 6.0 py38h2bbff1b_1 pyzmq 23.2.0 py38hd77b12b_0 qdarkstyle 3.0.2 pyhd3eb1b0_0 qstylizer 0.2.2 py38haa95532_0 qt-main 5.15.2 he8e5bd7_7 qt-webengine 5.15.9 hb9a9bb5_5 qtawesome 1.2.2 py38haa95532_0 qtconsole 5.4.0 py38haa95532_0 qtpy 2.2.0 py38haa95532_0 qtwebkit 5.212 h3ad3cdb_4 requests 2.28.2 pyhd8ed1ab_0 conda-forge rope 1.7.0 py38haa95532_0 rtree 1.0.1 py38h2eaa2aa_0 scipy 1.10.1 py38h0f6ee2a_0 conda-forge scyjava 1.9.0 pyhd8ed1ab_0 conda-forge setuptools 67.4.0 pyhd8ed1ab_0 conda-forge sip 6.6.2 py38hd77b12b_0 six 1.16.0 pyh6c4a22f_0 conda-forge snappy 1.1.9 hfb803bf_2 conda-forge snowballstemmer 2.2.0 pyhd3eb1b0_0 sortedcontainers 2.4.0 pyhd3eb1b0_0 soupsieve 2.3.2.post1 py38haa95532_0 sphinx 5.0.2 py38haa95532_0 sphinxcontrib-applehelp 1.0.2 pyhd3eb1b0_0 sphinxcontrib-devhelp 1.0.2 pyhd3eb1b0_0 sphinxcontrib-htmlhelp 2.0.0 pyhd3eb1b0_0 sphinxcontrib-jsmath 1.0.1 pyhd3eb1b0_0 sphinxcontrib-qthelp 1.0.3 pyhd3eb1b0_0 sphinxcontrib-serializinghtml 1.1.5 pyhd3eb1b0_0 spyder 5.4.1 py38haa95532_0 spyder-kernels 2.4.1 py38haa95532_0 sqlite 3.40.1 h2bbff1b_0 stack_data 0.2.0 pyhd3eb1b0_0 symlink-exe-runtime 1.0 hcfcfb64_0 conda-forge tbb 2021.7.0 h59b6b97_0 text-unidecode 1.3 pyhd3eb1b0_0 textdistance 4.2.1 pyhd3eb1b0_0 three-merge 0.1.1 pyhd3eb1b0_0 tifffile 2020.10.1 py38h8c2d366_2 tinycss2 1.2.1 py38haa95532_0 tk 8.6.12 h8ffe710_0 conda-forge toml 0.10.2 pyhd3eb1b0_0 tomli 2.0.1 py38haa95532_0 tomlkit 0.11.1 py38haa95532_0 tornado 6.2 py38h2bbff1b_0 traitlets 5.7.1 py38haa95532_0 typing-extensions 4.4.0 hd8ed1ab_0 conda-forge typing_extensions 4.4.0 pyha770c72_0 conda-forge ucrt 10.0.22621.0 h57928b3_0 conda-forge ujson 5.4.0 py38hd77b12b_0 unicodedata2 15.0.0 py38h91455d4_0 conda-forge unidecode 1.2.0 pyhd3eb1b0_0 urllib3 1.26.14 pyhd8ed1ab_0 conda-forge vc 14.3 hb6edc58_10 conda-forge vs2015_runtime 14.34.31931 h4c5c07a_10 conda-forge watchdog 2.1.6 py38haa95532_0 wcwidth 0.2.5 pyhd3eb1b0_0 webencodings 0.5.1 py38_1 whatthepatch 1.0.2 py38haa95532_0 wheel 0.38.4 pyhd8ed1ab_0 conda-forge win_inet_pton 1.1.0 py38haa244fe_5 conda-forge wrapt 1.14.1 py38h2bbff1b_0 xarray 2023.1.0 pyhd8ed1ab_0 conda-forge xorg-libxau 1.0.9 hcd874cb_0 conda-forge xorg-libxdmcp 1.1.3 hcd874cb_0 conda-forge xz 5.2.6 h8d14728_0 conda-forge yaml 0.2.5 he774522_0 yapf 0.31.0 pyhd3eb1b0_0 zeromq 4.3.4 hd77b12b_0 zfp 1.0.0 h63175ca_3 conda-forge zipp 3.15.0 pyhd8ed1ab_0 conda-forge zlib 1.2.13 h8cc25b3_0 zlib-ng 2.0.6 h8ffe710_0 conda-forge zstd 1.5.2 h19a0ad4_0

Traceback

Exception in comms call get_namespace_view:
  File "C:\Users\uqahine4\Anaconda3\envs\pyimagej\lib\site-packages\spyder_kernels\comms\commbase.py", line 317, in _comm_message
    buffer = cloudpickle.loads(msg['buffers'][0],
jpype._core.JVMNotRunning: Java Virtual Machine is not running

Exception in comms call get_var_properties:
  File "C:\Users\uqahine4\Anaconda3\envs\pyimagej\lib\site-packages\spyder_kernels\comms\commbase.py", line 317, in _comm_message
    buffer = cloudpickle.loads(msg['buffers'][0],
jpype._core.JVMNotRunning: Java Virtual Machine is not running

Versions

Dependencies

# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.31.1;<9.0.0       :  8.10.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.1 (OK)
jellyfish >=0.7               :  0.9.0 (OK)
jsonschema >=3.2.0            :  4.17.3 (OK)
keyring >=17.0.0              :  23.4.0 (OK)
nbconvert >=4.0               :  6.5.4 (OK)
numpydoc >=0.6.0              :  1.5.0 (OK)
paramiko >=2.4.0              :  2.8.1 (OK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.9.4 (OK)
pygments >=2.0                :  2.11.2 (OK)
pylint >=2.5.0;<3.0           :  2.16.2 (OK)
pylint_venv >=2.1.1           :  2.3.0 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.7.0;<1.8.0          :  1.7.1 (OK)
pylsp_black >=1.2.0           :  1.2.1 (OK)
qdarkstyle >=3.0.2;<3.1.0     :  3.0.2 (OK)
qstylizer >=0.2.2             :  0.2.2 (OK)
qtawesome >=1.2.1             :  1.2.2 (OK)
qtconsole >=5.4.0;<5.5.0      :  5.4.0 (OK)
qtpy >=2.1.0                  :  2.2.0 (OK)
rtree >=0.9.7                 :  1.0.1 (OK)
setuptools >=49.6.0           :  67.4.0 (OK)
sphinx >=0.6.6                :  5.0.2 (OK)
spyder_kernels >=2.4.1;<2.5.0 :  2.4.1 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.6 (OK)
zmq >=22.1.0                  :  23.2.0 (OK)

# Optional:
cython >=0.21                 :  None (NOK)
matplotlib >=3.0.0            :  3.7.0 (OK)
numpy >=1.7                   :  1.24.2 (OK)
pandas >=1.1.1                :  1.5.3 (OK)
scipy >=0.17.0                :  1.10.1 (OK)
sympy >=0.7.3                 :  None (NOK)
ccordoba12 commented 1 year ago

Hey @AdamDHines, thanks for reporting. You said:

The ij variable (a net.imagej.ImageJ object of imagej module) works fine, but trying to load a .tif image

What do you mean by this exactly? Did you try to load the image with or by doing a double-click on its corresponding entry in the Variable Explorer?

or perform any function with the ImageJ2 framework causes this Java Virtual Machine error to occur.

What kind of function are referring to? Please be more specific.

AdamDHines commented 1 year ago

Thanks for the reply, @ccordoba12

What I mean is that initializing ImageJ works without any error, with the following code.

import imagej; ij = imagej.init()

I believe this also initializes the Java Virtual Machine during the process.

The error specified occurs when trying to load an image with this code.

dataset = ij.io().open('/Users/Desktop/Test/Test-1.tif')

The variable dataset does not appear in the Variable Explorer.

I hope that clarifies things.

ccordoba12 commented 1 year ago

Hey @AdamDHines, thanks for the clarification. I was able to reproduce your problem and we'll try to fix it in a future release. For now, the only workaround I can offer you is to make dataset a private variable (i.e. renaming it to _dataset) so that the Variable Explorer keeps working for you.

@impact27, could you take a look at this one? The bug doesn't show up in master because of the new way the Variable Explorer is updated, but as soon as dataset is created, it stops being refreshed. It seems the issue is that cloudpickle is incorrectly serializing some comms data, which then it can't deserialize (that's the best insight I could get after a couple of hours researching this).

AdamDHines commented 1 year ago

Thanks for investigating, @ccordoba12. I can confirm that the workaround was successful for me. I asked this question in a few places and so I will answer them and link to this issue.