Import python packages in PyCharm

I want to develop scripts in PyCharm, because it’s more friendly for developing new scripts. However, the ImageJ packages aren’t installed in this compiler. How can I add the ImageJ packages to the compiler, so I can run scripts in a more convenient UI?

I can’t find the answers in FAQ’s or forum posts on the internet. I hope there’s a possibility to do this.

Is your intention to have autocomplete for ImageJ? As far as I know this is not possible with PyCharm, as all ImageJ packages are Java and PyCharm is not designed to develop Jython code with Java dependencies. A better solution could be to use eclipse with PyDev. There is a documentation on how to use Jython within eclipse. There is even a section about using Java libs.

1 Like

Thank you! I’m going to try that! I think I’ve to learn some java skills as well. At this moment I just don’t know enough about all the programming languages.

I’ve never used PyCharm, although this post led me to investigate a bit more and find this.

Anyhow, it seems to work if you install IntelliJ IDEA along with its Python extension. It looks like this gives you the Java support of IntelliJ + (more or less?) the Python support of PyCharm.

I have documented the process for setting up IntelliJ and QuPath for writing Groovy scripts here. I have tested it, and the same process basically works for setting up IntelliJ and Fiji as well (except that of course you link to Fiji’s ‘jars’ directory rather than QuPath’s).

Then you can install the Python extension to IntelliJ and start writing Python scripts with autocomplete.

However, if you do this, then I would recommend also trying out writing Groovy scripts as well. For me, Groovy is a much more comfortable fit with ImageJ/Fiji’s Java code than Python - and it would be more helpful if you are interested in converting any of your code to Java in the future… but I guess it’s a matter of personal preference.

Edit: I’ve seen there’s a bit more configuration to do in terms of Python setup to get autocomplete for Python itself - this StackOverflow discussion is helpful.

5 Likes