JVM 在 Spyder 5.4.1 中无法运行,使用 PyImageJ。

huangapple go评论150阅读模式
英文:

JVM not running in Spyder 5.4.1 using PyImageJ

问题

以下是您要翻译的文本部分:

  1. 我正在构建一款软件,并尝试在Spyder 5.4.1Python 3.8)和ImageJ宏之间结合我的分析脚本。我的数据集是一系列.tif堆栈图像,因此我决定使用PyImageJ来访问ImageJ2网关接口,以通过Spyder加载和运行我的ImageJ宏,从而在一个自动化脚本中执行分析。
  2. 我使用了这里描述的conda/mamba安装方法:https://pyimagej.readthedocs.io/en/latest/Install.html,并在Anaconda Navigator 2.3.2的Powershell提示符中进行了安装。
  3. 在调用`conda list`以查看创建的pyimagej环境时,显示必要的软件包已正确安装。我将环境更改为通过conda/mamba安装生成的环境,名为'pyimagej',然后从Anaconda Navigator中打开Spyder
  4. 我可以导入并连接到ImageJ2网关而没有问题。
  5. "连接到ImageJ2 API"
  6. import imagej
  7. ij = imagej.init()
  8. dataset = ij.io().open('/Desktop/Test/Test-1.tif')

但是,当尝试导入图像时,出现以下错误:

  1. comms调用get_namespace_view中的异常:
  2. 文件"\Anaconda3\envs\pyimagej\lib\site-packages\spyder_kernels\comms\commbase.py",第317行,在_comm_message
  3. buffer = cloudpickle.loads(msg['buffers'][0],
  4. jpype._core.JVMNotRunning: Java虚拟机未运行
  5. comms调用get_var_properties中的异常:
  6. 文件"\Anaconda3\envs\pyimagej\lib\site-packages\spyder_kernels\comms\commbase.py",第317行,在_comm_message
  7. buffer = cloudpickle.loads(msg['buffers'][0],
  8. jpype._core.JVMNotRunning: Java虚拟机未运行
  9. 尝试在初始化ImageJ2网关`ij = imagej.init()`之后启动新的JVM的以下代码告诉我JVM已经在运行。
  10. "启动JVM"
  11. import jpype
  12. import jpype.imports
  13. jpype.startJVM()
  14. Traceback (most recent call last):
  15. Cell In[7], line 4
  16. jpype.startJVM()
  17. 文件~\Anaconda3\envs\pyimagej\lib\site-packages\jpype\_core.py:166 in startJVM
  18. raise OSError('JVM is already started')
  19. OSError: JVM已经启动

为什么我会收到一个错误消息,指出JVM未运行,当它已经通过imagej.init()启动了?由于这个错误,我无法使用PyImageJ进行任何操作。

英文:

I am building a piece of software and trying to combine my analysis scripts between Spyder 5.4.1 (Python 3.8) and and ImageJ macros. My datasets are a series of .tif stack images, so I have decided to use PyImageJ to access the ImageJ2 gateway interface to load and run my ImageJ macros through Spyder to have the analysis performed in one automated script.

I utilised the installation method via conda/mamba described here https://pyimagej.readthedocs.io/en/latest/Install.html with the Powershell prompt from Anaconda Navigator 2.3.2

When calling conda list for the pyimagej environment created, it shows the necessary packages were installed correctly. I change the environment to the one generated from the conda/mamba installation, called 'pyimagej' and open Spyder from the Anaconda Navigator.

I can import and connect to the ImageJ2 gateway without issue.

  1. "Connect to the ImageJ2 API"
  2. import imagej
  3. ij = imagej.init()
  4. dataset = ij.io().open('/Desktop/Test/Test-1.tif')

However, when trying to import an image I get the following error.

  1. Exception in comms call get_namespace_view:
  2. File "\Anaconda3\envs\pyimagej\lib\site-packages\spyder_kernels\comms\commbase.py", line 317, in _comm_message
  3. buffer = cloudpickle.loads(msg['buffers'][0],
  4. jpype._core.JVMNotRunning: Java Virtual Machine is not running
  5. Exception in comms call get_var_properties:
  6. File "\Anaconda3\envs\pyimagej\lib\site-packages\spyder_kernels\comms\commbase.py", line 317, in _comm_message
  7. buffer = cloudpickle.loads(msg['buffers'][0],
  8. jpype._core.JVMNotRunning: Java Virtual Machine is not running

Trying to start a new JVM after initialising an ImageJ2 gateway ij = imagej.init() with the following code tells me a JVM is already running.

  1. "Start JVM"
  2. import jpype
  3. import jpype.imports
  4. jpype.startJVM()
  5. Traceback (most recent call last):
  6. Cell In[7], line 4
  7. jpype.startJVM()
  8. File ~\Anaconda3\envs\pyimagej\lib\site-packages\jpype\_core.py:166 in startJVM
  9. raise OSError('JVM is already started')
  10. OSError: JVM is already started

Why am I getting an error that states the JVM is not running when it has been started with imagej.init()? I cannot do anything with PyImageJ because of this error.

答案1

得分: 0

这是Spyder版本大于5.4.1中已知的问题,与变量资源管理器的更新有关(参见问题#20635)。已提出了一个修复方案,计划在Spyder 6发布时发布。

目前的解决方法是将data变量定义为私有变量,方法是更改代码为_data = ij.io().open(/'Test.tif')

经过测试,这个解决方法可以使PyImageJ在Spyder中正常使用图像。

英文:

This is now a reported and known bug in Spyder >5.4.1 and has to do with the updating of the variable explorer (see Issue #20635). A fix has been proposed with a goal for the release of Spyder 6.

The current workaround is to define the data variable as a private variable by changing the code to it _data = ij.io().open(/'Test.tif').

After testing this workaround, it allows PyImageJ to work with images just fine in Spyder.

huangapple
  • 本文由 发表于 2023年3月4日 09:26:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75633118.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定