So to preface this post, I realize that CellProfiler 4.0.0 is still under development, but I desperately need to use Python 3 with CellProfiler for a software package that I am developing. Therefore, I decided to download the latest CellProfiler code from GitHub, apt-get all of the various dependencies, build CellProfiler “from source”, and package it all as a Docker container. Somehow, I got this all working, and I’m even able to open the CellProfiler GUI via the Linux Docker container that my MacBook Pro is running (although there were a few bugs with the installation that I had to manually patch; I’m happy to share those if anyone is interested).
For the next step, I created a CellProfiler cell segmentation pipeline using the GUI, and then I exported it as a .cppipe file. Then, I tried to run the pipeline using CellProfiler as a Python package. I followed the guide at https://github.com/CellProfiler/CellProfiler/wiki/CellProfiler-as-a-Python-package; below is the script:
from cellprofiler_core.pipeline import Pipeline pipeline = Pipeline() pipeline.load("output/segment.cppipe") measurements = pipeline.run()
Unfortunately, this gives me the following Javabridge error:
Traceback (most recent call last): File "/home/jupyter-user/miniconda/envs/preprocessing/lib/python3.8/site-packages/cellprofiler_core/pipeline/_pipeline.py", line 1402, in prepare_run not module.prepare_run(workspace) File "/home/jupyter-user/miniconda/envs/preprocessing/lib/python3.8/site-packages/cellprofiler_core/modules/images.py", line 335, in prepare_run ifcls = javabridge.class_for_name("org.cellprofiler.imageset.ImageFile") File "/home/jupyter-user/miniconda/envs/preprocessing/lib/python3.8/site-packages/javabridge/jutil.py", line 1743, in class_for_name ldr = static_call('java/lang/ClassLoader', 'getSystemClassLoader', File "/home/jupyter-user/miniconda/envs/preprocessing/lib/python3.8/site-packages/javabridge/jutil.py", line 939, in static_call fn = make_static_call(class_name, method_name, sig) File "/home/jupyter-user/miniconda/envs/preprocessing/lib/python3.8/site-packages/javabridge/jutil.py", line 910, in make_static_call klass = env.find_class(class_name) AttributeError: 'NoneType' object has no attribute 'find_class'
However, if I run the pipeline in the command line headless mode, it works fine. Here is a GitHub issue that seems to express the exact same problem (albeit with CellProfiler v3.1.8):
If there was some method (whether in beta development or not) of running a CellProfiler pipeline from a Python script without running into this error, I would love to know about it.