Pyimagej failing with "'net.imagej.ops.OpService' object has no attribute 'run'"


I’m having trouble getting the ‘ImageJ-with-Python-Kernel’ jupyter notebook to run as expected. I’ve tried both a local install and also a Google Colab install of pyimagej and either approach fails at the same place in the same way.

import numpy as np
arr1 = np.array([[1, 2], [3, 4]])
arr2 = np.array([[5, 6], [7, 8]])
arr_output =


AttributeError                            Traceback (most recent call last)
<ipython-input-9-8db1978bb24f> in <module>()
      4 arr_output =
----> 6 ij.op().run('multiply',,,
      7 arr_output

AttributeError: 'net.imagej.ops.OpService' object has no attribute 'run'

The jupyter notebook demonstrating this is here: pyimagej_example.

Any suggestions appreciated.

This seems to be a problem with pyjnius. Version 1.2.1 has some issues, you need to use version 1.2.0. Thank you @imagejan.

1 Like

Thanks for updating this topic.

Usually, it’s a good idea to disclose when cross-posting similar subjects to various places. For others stumbling upon this topic, here are the relevant GitHub issues where this was discussed:

@ctrueden I’m tagging you here as you seem to be the one that has built a lot of this software.

Right so I’ve installed imageJ in a new conda environment as detailed in GitHub tutorials page. I did this because I was initially having issues with imagej in PyCharm IDE (because I installed pyimagej with pip install pyimagej command)

Then, I was working my way through this ImageJ-Python Jupyter notebook and encountered errors when trying to run cell [11]

AttributeError: 'net.imagej.ops.OpService' object has no attribute 'run'

That was the error I was getting. Which led me to this thread. OK - switch pyjnius from 1.2.1 to 1.2.0. Seems straightforward, but in reality not so much (maybe because I am a complete beginner). Anyways, finally managed to install pyjnius 1.2.0, but conda had to remove (including pyimagej which I re-installed later), update and install several packages in the process.

I go on the same jupyter notebook as before, and now it’s asking me to install Java version 6!

This is a never-ending hole of installations, update, changing version, delete, try again, error. All of this just ot get pyimagej to work on conda because it wasn’t working in PyCharm/with pip in the first place.
In summary, very frustrating.

I appreciate that you have worked a lot on this, and it seems very promising software (hence why I am here). But I feel as though there are always small errors that impede me from using it.

If you have any recommendations as to what to do to get thins to actually work - they are more than welcomed. Otherwise, I think I might have to head back to MATLAB and do all my image analysis there unfortunately :frowning:

No offense intended (it’s just that I spent the last 5 hours maybe? trying to get pyimagej to work, without success).

One thing that might help is to use pip instead of conda to just downgrade the pyjnius package, see install specific version with pip.

So basically you’d have to start over again, but then once you had gone through installing and activating the new conda environment and got back to the original error message, you’d only downgrade pyjnius using pip which would leave everything else the same and then hopefully it would work…

Hi @Hazen_Babcock,

Have restarted from scratch; I created a new conda environmented as per the guidelines on the pyimagej Git repo.

With the command conda install pyimagej=1.2.0 I managed to downgrade to version 1.2.0 without anything else to be amended by conda.

But I am falling back on the same error found as before: see screenshot below

Screenshot 2020-04-25 at 11.52.44

My impression is that people have figured out a solution to this which has been added to pyjnius 1.2.1. Bu then I still don’t know how to get round the error previously mentioned.

AttributeError: 'net.imagej.ops.OpService' object has no attribute 'run'

I guess it’s better to have some ImageJ functionality (with pyjnius 1.2.1) vs none at all (with pyjnius 1.2.0). Although I have just realised that the .op() has no attributes at all… Making the installation of pyimagej redundant in my case unfortunately.

Thanks for your response though

Hi @pablooriol2,

The install Java SE 6 runtime error is a known issue on Mac. You can work around the issue by editing the Info.plist of any one of your Java installations as outlined here:

I encountered the same issue when setting this up myself. I would definitely recommend sticking with pyjunius 1.2.0. If you use 1.2.1 you will not have access to functionality in super class methods as described above.

I am not sure the origin of the OpService has no attribute error you see. There are certainly a lot of little issues that can come up when configuring the environment. All I can say is that we have successfully set this up on several computers and find it to be a very wonderful bridge from the java world to the python world. All of my experience is with jupiter notebooks. Is that where you got the error?


Hi @karlduderstadt,

Your reply is a godsend! It’s working now! :slight_smile: Thank you so much.

I don’t know why I hadn’t come across that topic… But indeed it proved to be crucial. I was aware that I had to add <string>JNI<string> to the Info.plist file. But I had no idea where to find this so-called Info.plist file (even though I knew it was related to Java) and so ended up just searching info.plist in the mac finder app, showed up with some info.plist files and opened some of them and added <string>JNI<string> somewhere (had no idea where in the file it had to go). Obviously, did this not work. So I gave up on that - until your reply.

In summary - thanks for sharing that topic as @ctrueden explains in detail how to ‘hack’ the system’s Java Info.plist file.

Regarding this:

Yes - I’ve mainly been testing pyimagej with jupyter notebooks. I may have tried it in the terminal or in a script in Pycharm too, but mainly just jupyter tbh. I assume that if it works in jupyter it’ll work in any place as long as you’re using Python :slight_smile:

Again thanks loads!