Skip to content

TypeError: 'NoneType' object is not callable when initializing imagej #308

Open
@belenal

Description

@belenal

This is my code:

import scyjava as sj

def print_classpath():
    System = sj.jimport('java.lang.System')
    import re
    classpath = re.split('[:;]', str(System.getProperty('java.class.path')))
    print("\n".join(classpath))

sj.when_jvm_starts(print_classpath)

import imagej

import jpype
import jpype.imports
from jpype.types import *

jvm_path = "C:\\Program Files\\Eclipse Adoptium\\jdk-8.0.362.9-hotspot\\jre\\bin\\server\\jvm.dll"

if not jpype.isJVMStarted():
    jpype.startJVM(jvm_path, "-ea")
    print("JVM started successfully!")

if jpype.isJVMStarted():
    print("JVM is running!")
else:
    raise RuntimeError("Failed to start JVM")

ij = imagej.init()
print("ImageJ initialized successfully!")

and I am getting:

JVM started successfully!
JVM is running!
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_18744\3541298497.py in <module>
     29 
     30 
---> 31 ij = imagej.init(['net.imagej:imagej:2.1.0', 'net.imagej:imagej-legacy'])
     32 
     33 # Inicializar Fiji

c:\Users\\AppData\Local\Programs\Python\Python37\lib\site-packages\imagej\__init__.py in init(ij_dir_or_version_or_endpoint, mode, add_legacy, headless)
   1236     else:
   1237         # HEADLESS or INTERACTIVE mode: create the gateway and return it.
-> 1238         return _create_gateway()
   1239 
   1240 

c:\Users\\AppData\Local\Programs\Python\Python37\lib\site-packages\imagej\__init__.py in _create_gateway()
   1266         return False
   1267 
-> 1268     ij = ImageJ()
   1269 
   1270     # Forward stdout and stderr from Java to Python.

TypeError: 'NoneType' object is not callable

I am using python 3.7.9.
I also tried using Python 3.9 and downloading pyimagej from github, and I get:

TypeError                                 Traceback (most recent call last)
Cell In[1], [line 31](vscode-notebook-cell:?execution_count=1&line=31)
     [27](vscode-notebook-cell:?execution_count=1&line=27) else:
     [28](vscode-notebook-cell:?execution_count=1&line=28)     raise RuntimeError("Failed to start JVM")
---> [31](vscode-notebook-cell:?execution_count=1&line=31) ij = imagej.init()
     [33](vscode-notebook-cell:?execution_count=1&line=33) # Inicializar Fiji
     [34](vscode-notebook-cell:?execution_count=1&line=34) #ij = imagej.init(["net.imagej:imagej", "sc.fiji:fiji", "org.morphonets:SNT:4.2.1"])
     [35](vscode-notebook-cell:?execution_count=1&line=35) #ij = imagej.init('C:/Users//Downloads/Fiji.app/Fiji.app/')  # Ajusta el path a la ubicación de tu instalación de Fiji
     [36](vscode-notebook-cell:?execution_count=1&line=36) #ij = imagej.init('C:\\Users\\\\Downloads\\fiji-win64\\Fiji.app')
     [37](vscode-notebook-cell:?execution_count=1&line=37) #ij = imagej.init('C:\\Users\\\\Downloads\\ij154-win-java8\\ImageJ')
     [38](vscode-notebook-cell:?execution_count=1&line=38) print("ImageJ initialized successfully!")

File c:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\imagej\__init__.py:1249, in init(ij_dir_or_version_or_endpoint, mode, add_legacy, headless)
   [1246](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/imagej/__init__.py:1246)         return None
   [1247](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/imagej/__init__.py:1247) else:
   [1248](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/imagej/__init__.py:1248)     # HEADLESS or INTERACTIVE mode: create the gateway and return it.
-> [1249](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/imagej/__init__.py:1249)     return _create_gateway()

File c:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\imagej\__init__.py:1279, in _create_gateway()
   [1270](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/imagej/__init__.py:1270)     _logger.error(
   [1271](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/imagej/__init__.py:1271)         "***Invalid initialization: ImageJ2 was not found***\n"
   [1272](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/imagej/__init__.py:1272)         "Please update your initialization call to include an ImageJ2 "
   (...)
   [1275](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/imagej/__init__.py:1275)         "be started once."
...
   [1281](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/imagej/__init__.py:1281) # Register a Python-side script runner object, used by the
   [1282](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/imagej/__init__.py:1282) # org.scijava:scripting-python script language plugin.
   [1283](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/imagej/__init__.py:1283) if callable(getattr(sj, "enable_python_scripting", None)):

TypeError: 'NoneType' object is not callable

I used doctor checkup and everything looks fine:

Checking Python:
--> Python executable = [c:\Users\\AppData\Local\Programs\Python\Python39\python.exe](file:///C:/Users//AppData/Local/Programs/Python/Python39/python.exe)

Checking environment:
--> It looks like you are NOT running inside a Conda environment.

Checking Python dependencies:
--> jgo: [c:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\jgo\__init__.py](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/jgo/__init__.py)
--> scyjava: [c:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\scyjava\__init__.py](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/scyjava/__init__.py)
--> imglyb: [c:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\imglyb\__init__.py](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/imglyb/__init__.py)
--> pyimagej: [c:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\imagej\__init__.py](file:///C:/Users//AppData/Local/Programs/Python/Python39/lib/site-packages/imagej/__init__.py)

Checking Maven:
--> Maven executable = [C:\Users\\Downloads\apache-maven-3.9.8-bin\apache-maven-3.9.8\bin\mvn.CMD](file:///C:/Users//Downloads/apache-maven-3.9.8-bin/apache-maven-3.9.8/bin/mvn.CMD)
$ mvn -v
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: [C:\Users\\Downloads\apache-maven-3.9.8-bin\apache-maven-3.9.8](file:///C:/Users//Downloads/apache-maven-3.9.8-bin/apache-maven-3.9.8)
Java version: 1.8.0_362, vendor: Temurin, runtime: [C:\Program](file:///C:/Program) Files\Eclipse Adoptium\jdk-8.0.362.9-hotspot\jre
Default locale: es_ES, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Checking Java:
--> JAVA_HOME = [C:\Program](file:///C:/Program) Files\Eclipse Adoptium\jdk-8.0.362.9-hotspot
--> Java executable = [C:\Program](file:///C:/Program) Files\Eclipse Adoptium\jdk-8.0.362.9-hotspot\bin\java.EXE
...
OpenJDK 64-Bit Server VM (Temurin)(build 25.362-b09, mixed mode)

Questions and advice for you:
--> Did you intend to activate a Conda environment?

Any idea what might be the problem? I have tried all the possible initializations endpoints and I keep getting the same error.
Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions