imagej / pyimagej

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

package not recognized on Windows 10 using conda env, cannot resolve java version #261

Closed nakajimayoshi closed 1 year ago

nakajimayoshi commented 1 year ago

Windows version: 10.0.19045.2604 Conda version: 23.3.1 Python: 3.10 pip: 23.1.2 IDE: PyCharm Professional 23.1.2 Editor: VSCode V 0.3.3 93b7cc4

Install method: exactly as outlined here

I have made several attempts to get this package working but all have lead me to dead ends. The issue is despite having the build files, packages, and activated environment, my IDE cannot find the "imagej" module. I'm not quite sure what's wrong as I have maven and the jdk installed, this appears when I type mvn in powershell:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.079 s
[INFO] Finished at: 2023-05-18T13:33:18+09:00
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: pre-clean, clean, post-c
lean, validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, pr
epare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException

typing javac -version yields: javac 17.0.3

I can see the pyimagej folder installed in my conda environment, located at C:\Users\user\anaconda3\pkgs\pyimagej-1.4.1-py38haa244fe_0

I can tell the pyimagej environment is activated denoted by the parenthesis at the beginning of the powershell prompt (pyimagej) C:\Users\user\PycharmProjects\kymograph-generator>

typing pip install pyimagej yields a long list of 'requirement already satisfied' responses of the sub-dependencies.

Ok, so perhaps something is misconfigured in the IDE, I'll try an editor to narrow down the issue. I open the python project with the exact same conda environment using VSC instead of PyCharm. I tried running the following code in VSC:

import imagej

ij = imagej.init()

image_url = 'https://imagej.net/images/clown.jpg'
jimage = ij.io().open(image_url)

image = ij.py.from_java(jimage)

if __name__ == '__main__':
    ij.py.show(image, cmap='gray')

first I get a "JAVA_HOME" not found error, so I have to manually configure env variables to point to the JDK. After doing so I get this:

PS C:\Users\user\PycharmProjects\kymograph-generator> & C:/Users/user/AppData/Local/Programs/Python/Python310/python.exe c:/user/single-molecule/PycharmProjects/kymograph-generator/main.py
Failed to guess the Java version.

typing java -version instead of javac -version this time we get:

openjdk version "17.0.7" 2023-04-18 LTS
OpenJDK Runtime Environment Zulu17.42+19-CA (build 17.0.7+7-LTS)
OpenJDK 64-Bit Server VM Zulu17.42+19-CA (build 17.0.7+7-LTS, mixed mode, sharing)

and that is where the trail ends for me. Hope one day this package can be installed via a simple pip install as I really have a lot of issues with the imagej macro language to get simple things done.

ctrueden commented 1 year ago

@nakajimayoshi Two questions for you:

From the command line, with the pyimagej environment activated, what happens when you run:

python -c 'import imagej; ij = imagej.init(); print(ij.getVersion())'

Does it work? Do you see e.g. "2.13.1" or similar version string printed?

If it works from the command line, but not from your IDE, then it's an issue with how your IDE is configured.

To use a conda environment in PyCharm, you can double-tap shift to bring up the "search everywhere" box, type in "Project structure", and hit enter, which should bring up the dialog box allowing to configure your SDK. The Python SDK you need is an existing conda environment, the one named pyimagej. Point it to your python.exe executable inside the conda environment. One way to find that python.exe location is from the command line while pyimagej is activated:

Get-Item Env:CONDA_PREFIX

Or with cmd.exe:

echo %CONDA_PREFIX%

I hope that helps. Happy to help troubleshoot further if needed; just reopen this issue with any additional questions.