Imagej.init() isn't working

I’m using a PC.

I activated the imagej environment in conda.
I imported “imagej” using import imagej.
I tried creating a new env using this " conda create -n imagej pyimagej"

When I run imagej.init() method, this error is thrown - "TypeError: init() missing 1 required positional argument: ‘ij_dir’ "

I then added the directory, “C:\Users\NT3130\Desktop\Fiji.app” . Then this error is thrown -
“Added 380 JARs to the Java classpath.”
and then the rest of the error is this below.
INFO 2019-03-26 17:00:28,514: Failed to bootstrap the artifact.
INFO 2019-03-26 17:00:32,928:
INFO 2019-03-26 17:00:32,939: Possible solutions:
INFO 2019-03-26 17:00:32,939: * Double check the endpoint for correctness (https://search.maven.org/).
INFO 2019-03-26 17:00:32,939: * Add needed repositories to ~/.jgorc [repositories] block (see README).
INFO 2019-03-26 17:00:32,940: * Try with an explicit version number (release metadata might be wrong).

Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\NT3130\AppData\Roaming\Python\Python37\site-packages\imagej\imagej.py”, line 70, in init
import imglyb
File “C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\lib\site-packages\imglyb_init_.py”, line 41, in
config, _ = init_jvm_options()
File "C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\lib\site-packages\imglyb_init
.py", line 36, in init_jvm_options
import scyjava
File "C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\lib\site-packages\scyjava_init
.py", line 55, in
jnius = init_jvm()
File "C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\lib\site-packages\scyjava_init
.py", line 41, in _init_jvm
verbose=scyjava_config.get_verbose()
File “C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\lib\site-packages\jgo\jgo.py”, line 457, in resolve_dependencies
raise e
File “C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\lib\site-packages\jgo\jgo.py”, line 448, in resolve_dependencies
mvn_out = run_and_combine_outputs(mvn, *mvn_args)
File “C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\lib\site-packages\jgo\jgo.py”, line 205, in run_and_combine_outputs
return subprocess.check_output((command,) + args, stderr=subprocess.STDOUT)
File “C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\lib\subprocess.py”, line 389, in check_output
**kwargs).stdout
File “C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\lib\subprocess.py”, line 481, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command ‘(‘C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\Library\bin\mvn.CMD’, ‘-B’, ‘-f’, ‘C:\Users\NT3130\.jgo\net\imglib\imglib2-imglyb\0.3.0\pom.xml’, ‘dependency:resolve’)’ returned non-zero exit status 1.

Can anyone offer help with this?

You should be able to call imagej.init() with the latest version of ImageJ without an argument. Is your pyimagej updated to the latest version?

I’m not sure about the second error, but let us know if it occurs in the latest version.

I believe I have the latest version of imagej
version = ‘0.4.0’

I checked the version using this path
C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\lib\site-packages\imagej\imagej.py

When I activate the environment, is it possible that i’m not activating the latest version? How can I check this? to activate I writer (conda activate imagej)

Thanks.

4.0 is the latest version and should work.

What interface are you importing ImageJ from? I’ve just tried this in Jupyter Notebook, but maybe there’s an issue if you’re using the ipython shell or a script.

I also made a new environment to test this, and found that the command - conda create -n imagej pyimagej should be conda create -n imagej -c conda-forge pyimagej, in order to download pyimagej. It looks like you are importing it correctly though so I don’t know if this matters.

I just tried it in jupyter note in a pyhton kernel but I still receive the same error.

This is what I receive when I activate the imagej env.

C:\Users\NT3130>SET PYJNIUS_JAR=

C:\Users\NT3130>SET PYJNIUS_JAR_BACKUP=’’

C:\Users\NT3130>SET PATH=C:\Users\NT3130\AppData\Local\Continuum\anaconda3;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\Library\mingw-w64\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\Library\usr\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\Library\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\Scripts;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\condabin;C:\Users\NT3130\AppData\Local\Scripts;C:\Users\NT3130\AppData\Local;;C:\Users\NT3130\AppData\Local\Programs\Microsoft VS Code\bin

C:\Users\NT3130>SET PATH_BACKUP=’’

C:\Users\NT3130>set “JAVA_HOME=”

C:\Users\NT3130>set “JAVA_HOME_CONDA_BACKUP=”

C:\Users\NT3130>set “JAVA_HOME_CONDA_BACKUP=”

C:\Users\NT3130>set “JAVA_HOME=C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\Library”

C:\Users\NT3130>SET “PYJNIUS_JAR_BACKUP=”

C:\Users\NT3130>SET “PYJNIUS_JAR=C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\share\pyjnius\pyjnius.jar”

C:\Users\NT3130>SET “PATH_BACKUP=C:\Users\NT3130\AppData\Local\Continuum\anaconda3\Library\jre\bin\server;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\Library\bin\server;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\Library\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\Library\mingw-w64\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\Library\usr\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\Library\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\Scripts;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\condabin;C:\Users\NT3130\AppData\Local\Scripts;C:\Users\NT3130\AppData\Local;;C:\Users\NT3130\AppData\Local\Programs\Microsoft VS Code\bin”

C:\Users\NT3130>SET “PATH=C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\Library\jre\bin\server;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\Library\bin\server;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\Library\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\Library\jre\bin\server;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\Library\bin\server;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\Library\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\Library\mingw-w64\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\Library\usr\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\Library\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\Scripts;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\envs\imagej\bin;C:\Users\NT3130\AppData\Local\Continuum\anaconda3\condabin;C:\Users\NT3130\AppData\Local\Scripts;C:\Users\NT3130\AppData\Local;;C:\Users\NT3130\AppData\Local\Programs\Microsoft VS Code\bin”
‘chcp’ is not recognized as an internal or external command,
operable program or batch file.

(imagej) c: \Users\NT3130 >

‘chcp’ is not recognized as an internal or external command,
operable program or batch file.

Is this import? Is it a path problem?

Thanks

I’m stumped on the main error, but ‘chcp’ is a path problem. You don’t seem to have System32 on your path, which may be part of the problem.

Yeah I am stumped. I tried everything I’ve seen on the internet. Is it possible to access the fiji API through the regular python kernel without anaconda ? If I just have python downloaded.

It is very bizarre because at first I had it working just from the python shell and installed the imagej module and I was able to write script in the python IDLE and run fiji through it. After installing anaconda I can no longer do so.

This is the original code that I used at first in python and it worked perfectly.
Now the error can’t find ij module is thrown.

from __future__ import with_statement, division
# This imports the function random from the module random.
from random import random
# Next we import Java Classes into Jython.
# This is how we can acces the ImageJ API:
# https://imagej.nih.gov/ij/developer/api/allclasses-noframe.html
from ij import IJ, WindowManager


import os
os.chdir('C:\\Users\\NT3130\\Desktop\\pics')
print(os.getcwd())

a = list(range(1,3))

for i in a:
	st = str(i); 
	IJ.open("40cP" + st + "RPM.jpg")
	IJ.run("Rotate 90 Degrees Right");
	IJ.run("Rotate 90 Degrees Right");
	IJ.saveAs("Jpeg", "C:/Users/NT3130/Desktop/pics/" + st);

I don’t think this mystery will ever be solved

Anaconda is not necessary for the Fiji API. It might be installing some sort of package erroneously; it’s hard to say because I can’t replicate your bugs.

The last bit of code is actually not for normal python or pyimageJ, it is for the Jython script interface inside the ImageJ program. The pyimagej module interfaces with the java code, and you can see some examples of that here.

Yes, what I mean is that last bit of code I ran through the python kernel and not jython script editor in the imagej software, and it worked.