imagej / pyimagej

Use ImageJ from Python
https://pyimagej.readthedocs.io/
Other
470 stars 81 forks source link

Installation instructions incomplete & example code misleading #38

Closed haesleinhuepf closed 5 years ago

haesleinhuepf commented 5 years ago

Dear all,

I was just struggling to get started with pyimagej on Windows. I'm documenting the issue here hoping that the documentation can be improved in order to lower the entry-level boundary. Details can be found here

import imagej
ij = imagej.init('2.0.0-rc-68')
print(ij.getVersion())

I hope that helps!

Cheers, Robert

haesleinhuepf commented 5 years ago

Addendum: Regarding the code example: How would the procedure shown in this notebook look like in pyimagej? https://git.mpi-cbg.de/rhaase/lecture_applied_bioimage_analysis/blob/master/07_examples/python/ImageProcessingInPython.ipynb

ctrueden commented 5 years ago

The installation instructions are incomplete. Either it is necessary to create an environment variable JAVA_HOME or it is necessary to install maven before the first pyimagej program runs.

Shouldn't be. Not if you use conda. There are conda packages for both openjdk and maven.

The very first example located here doesn't work as expected.

I'm sorry, I don't understand what you mean by "expected" here. What doesn't happen, that you expect should happen?

Would it be possible to have first a code example which does something like: Thresholding blobs.gif, counting cells and measuring their size?

I think that is too complex for a first code example. But I agree it would be a great code example, introduced relatively early. However, it takes work to figure out how to do those things. Do you have time to figure it out, and report any problems you find? I expect there will be several obstacles.

I would love to see how to play with ImageJ images and ROIs using ImageJ-methods called from python before complicated mixtures of numpy-ImageJ-conversions are introduced.

I agree that showing ROIs would be good. However, please keep in mind the target audience for this project: people who want to mix in ImageJ to PyData-based workflows. That means the people we're targeting already know NumPy, and the first thing they'll want to know is "how do I hand my NumPy image to ImageJ?" On the flip side: people who don't know PyData are unlikely to care so much about PyImageJ, since there are easier and more battle-tested ways of calling ImageJ via scripts than to use CPython via this bridge layer.

haesleinhuepf commented 5 years ago

Hi again,

I just tried to install it on another Windows machine. The error message of pip install pyimagej run from anaconda promt in admin-mode is:

Installing collected packages: pyjnius
  Running setup.py install for pyjnius ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\programdata\anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\rhaase\\AppData\\Local\\Temp\\pip-install-n3pqfd2b\\pyjnius\\setup.py'"'"'; __file__='"'"'C:\\Users\\rhaase\\AppData\\Local\\Temp\\pip-install-n3pqfd2b\\pyjnius\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\rhaase\AppData\Local\Temp\pip-record-t4uuox_w\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\rhaase\AppData\Local\Temp\pip-install-n3pqfd2b\pyjnius\
    Complete output (34 lines):
    C:\ProgramData\Anaconda3\Library
    WARNING: Not able to assign machine() = AMD64 to a cpu value!
             Using cpu = 'i386' instead!
    JDK_HOME: C:\ProgramData\Anaconda3\Library

    JRE_HOME: C:\ProgramData\Anaconda3\Library\jre

    warning: [options] bootstrap class path not set in conjunction with -source 1.6
    1 warning
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.7
    copying jnius_config.py -> build\lib.win-amd64-3.7
    creating build\lib.win-amd64-3.7\jnius
    copying jnius\reflect.py -> build\lib.win-amd64-3.7\jnius
    copying jnius\signatures.py -> build\lib.win-amd64-3.7\jnius
    copying jnius\__init__.py -> build\lib.win-amd64-3.7\jnius
    creating build\lib.win-amd64-3.7\jnius\src
    creating build\lib.win-amd64-3.7\jnius\src\org
    creating build\lib.win-amd64-3.7\jnius\src\org\jnius
    copying jnius\src\org\jnius\NativeInvocationHandler.class -> build\lib.win-amd64-3.7\jnius\src\org\jnius
    copying jnius\src\org\jnius\NativeInvocationHandler.java -> build\lib.win-amd64-3.7\jnius\src\org\jnius
    running build_ext
    skipping 'jnius\jnius.c' Cython extension (up-to-date)
    building 'jnius' extension
    creating build\temp.win-amd64-3.7
    creating build\temp.win-amd64-3.7\Release
    creating build\temp.win-amd64-3.7\Release\jnius
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\ProgramData\Anaconda3\Library\include -IC:\ProgramData\Anaconda3\Library\include\win32 -Ic:\programdata\anaconda3\include -Ic:\programdata\anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" /Tcjnius\jnius.c /Fobuild\temp.win-amd64-3.7\Release\jnius\jnius.obj
    jnius.c
    C:\ProgramData\Anaconda3\Library\include\jni.h(45): fatal error C1083: Cannot open include file: 'jni_md.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\programdata\anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\rhaase\\AppData\\Local\\Temp\\pip-install-n3pqfd2b\\pyjnius\\setup.py'"'"'; __file__='"'"'C:\\Users\\rhaase\\AppData\\Local\\Temp\\pip-install-n3pqfd2b\\pyjnius\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\rhaase\AppData\Local\Temp\pip-record-t4uuox_w\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

(base) C:\WINDOWS\system32>

I tried to fix this by installing pyjnius (which worked as described on their website) but it doesn't help. The error message stayed the same.

I'm now trying to install via linux subsystem....

haesleinhuepf commented 5 years ago

Sorry. My fault. pyjnius had issues comiling. Maybe related to this issue I made it work by calling

set PATH=%PATH%;C:\Program Files\Java\jdk1.8.0_161\jre\bin\server

copy "C:\Program Files\Java\jdk1.8.0_161\include\win32\jni_md.h" c:\ProgramData\Anaconda3\Library\include

python -m pip install --upgrade pip setuptools

python -m pip install --upgrade cython

pip install pyjnius

pip install pyimagej

Feel free to put that somewhere in a troubleshooting section ;-)

haesleinhuepf commented 5 years ago

One more thing: In the installation instructions it says:

conda env create -f environment.yml

But that file environment.jml doesn't exist... I'm searching for it now...

haesleinhuepf commented 5 years ago

Ok, after some additional trouble, I made it run on windows using Anaconda. The full installation command list is:

set PATH=%PATH%;C:\Program Files\Java\jdk1.8.0_161\jre\bin\server
copy "C:\Program Files\Java\jdk1.8.0_161\include\win32\jni_md.h" c:\ProgramData\Anaconda3\Library\include
python -m pip install --upgrade pip setuptools
python -m pip install --upgrade cython
pip install pyjnius
pip install pyimagej

set "JDK_HOME=C:\Program Files\Java\jdk1.8.0_161\"

pip install jnius

# get the environment.yml file from: https://raw.githubusercontent.com/imagej/pyimagej/master/environment.yml
conda env create -f environment.yml

conda activate imagej

pip install pyimagej
pip install scikit-image
pip install scipy

Maybe that helps.

Cheers, Robert

ctrueden commented 5 years ago

In the installation instructions it says:

conda env create -f environment.yml

But that file environment.jml doesn't exist...

It's a YAML file: environment.yml, here.

But those installation instructions are only for the pip-installable version of pyimagej. I strongly encourage you to use the conda version, and avoid pip installation of this package.

I made it run on windows using Anaconda.

Why are you using pip commands? You should not need any. All is available from conda-forge. It should be installable via:

conda create -n imagej pyimagej openjdk=8
conda activate imagej

If that doesn't work on Windows, please file a new issue with details of what goes wrong.

haesleinhuepf commented 5 years ago

Hey @ctrueden ,

I just posted about what's going wrong on Windows above https://github.com/imagej/pyimagej/issues/38#issuecomment-524605904

And the solution further down. https://github.com/imagej/pyimagej/issues/38#issuecomment-524609578

Furthermore, I'm using pip, because that's what I found when googling for pyimagej. I landed on that website: image

Feel free to copy my solution to a trouble-shooting section of the documentation.

I will create another issue about installation on Ubuntu.

Thanks for your support!

Cheers, Robert

imagejan commented 5 years ago

@haesleinhuepf from my own experience with Python on Windows, I'd recommend to:

In my trials on Windows 10, the following worked (from Anaconda Prompt):

conda env create -f environment.yml
conda activate imagej
conda install pyimagej -c conda-forge

(or, in a similar way, without any environment.yml, by just specifying pyimagej and letting conda figure out all dependencies:

conda create -n imagej-test -c conda-forge pyimagej openjdk=8
conda activate imagej-test

)

Then the simple test script works via command-line python:

python
>>> import imagej
>>> ij = imagej.init()
>>> ij.getVersion()

It still doesn't work from jupyter notebook however, because the Jupyter kernel doesn't activate the environment in the same way. That's why you need these additional lines in a notebook (as detailed in https://github.com/imagej/pyimagej/issues/21#issuecomment-482702294 by @ctrueden):

import sys
!conda install --yes --prefix {sys.prefix} -c conda-forge pyimagej openjdk=8

I think all this is not yet well reflected in the README, and we should try to update it as soon as possible (and before demoing it at the NEUBIAS Training School...).

ctrueden commented 5 years ago

I think all this is not yet well reflected in the README

As discussed in #45, the README is better now.

As of scyjava 0.2.3, pyimagej should also now have fewer problems on Windows; see scijava/scyjava@35010bb6d0634ee6942275440b915d458eb419b3.