英文:
JVM not running in Spyder 5.4.1 using PyImageJ
问题
以下是您要翻译的文本部分:
我正在构建一款软件,并尝试在Spyder 5.4.1(Python 3.8)和ImageJ宏之间结合我的分析脚本。我的数据集是一系列.tif堆栈图像,因此我决定使用PyImageJ来访问ImageJ2网关接口,以通过Spyder加载和运行我的ImageJ宏,从而在一个自动化脚本中执行分析。
我使用了这里描述的conda/mamba安装方法:https://pyimagej.readthedocs.io/en/latest/Install.html,并在Anaconda Navigator 2.3.2的Powershell提示符中进行了安装。
在调用`conda list`以查看创建的pyimagej环境时,显示必要的软件包已正确安装。我将环境更改为通过conda/mamba安装生成的环境,名为'pyimagej',然后从Anaconda Navigator中打开Spyder。
我可以导入并连接到ImageJ2网关而没有问题。
"连接到ImageJ2 API"
import imagej
ij = imagej.init()
dataset = ij.io().open('/Desktop/Test/Test-1.tif')
但是,当尝试导入图像时,出现以下错误:
在comms调用get_namespace_view中的异常:
文件"\Anaconda3\envs\pyimagej\lib\site-packages\spyder_kernels\comms\commbase.py",第317行,在_comm_message
buffer = cloudpickle.loads(msg['buffers'][0],
jpype._core.JVMNotRunning: Java虚拟机未运行
在comms调用get_var_properties中的异常:
文件"\Anaconda3\envs\pyimagej\lib\site-packages\spyder_kernels\comms\commbase.py",第317行,在_comm_message
buffer = cloudpickle.loads(msg['buffers'][0],
jpype._core.JVMNotRunning: Java虚拟机未运行
尝试在初始化ImageJ2网关`ij = imagej.init()`之后启动新的JVM的以下代码告诉我JVM已经在运行。
"启动JVM"
import jpype
import jpype.imports
jpype.startJVM()
Traceback (most recent call last):
Cell In[7], line 4
jpype.startJVM()
文件~\Anaconda3\envs\pyimagej\lib\site-packages\jpype\_core.py:166 in startJVM
raise OSError('JVM is already started')
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.
"Connect to the ImageJ2 API"
import imagej
ij = imagej.init()
dataset = ij.io().open('/Desktop/Test/Test-1.tif')
However, when trying to import an image I get the following error.
Exception in comms call get_namespace_view:
File "\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 "\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
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.
"Start JVM"
import jpype
import jpype.imports
jpype.startJVM()
Traceback (most recent call last):
Cell In[7], line 4
jpype.startJVM()
File ~\Anaconda3\envs\pyimagej\lib\site-packages\jpype\_core.py:166 in startJVM
raise OSError('JVM is already started')
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论