4

Using Python 2.7 on Mac, and IDE is PyCharm. Need to use some Java functions inside Python script, and prefer to use import of Python, for example from com.a.b.c import fooFunc, so that I can use fooFunc in Python script as a Python function. The Java functions are defined in goo.jar.

My question is, where should I place the goo.jar file, so that Python/PyCharm could find the jar file?

Edit 1, add screen snapshot for PyDev for Jython project,

enter image description here enter image description here

Edit 2, add screen snapshot for auto-config error message,

enter image description here

Edit 3, cannot select installed jython interpreter from Eclipse, enter image description here enter image description here

Edit 4, can only select .jar file when configuring jython interpreter,

enter image description here

Edit 5, program runs ok but with red alert error messages from console,

enter image description here

enter image description here

7
  • 3
    Python by itself has no wrappers around the java framework, therefore there is no way for it to import java classes or use java methods. You need to make use of jython. The jython book has a chapter on how to use jython in an IDE Commented Jul 4, 2016 at 22:11
  • @khredos, thanks and vote up. I followed the guide and confused by the following statement, Once you have selected the ‘Interpreter – Jython’ section, you will be presented with an empty list of Jython interpreters at the top of the right side. We clearly need to fix that! So, click the New button, enter ‘Jython 2.5.1’ as the Interpreter Name, click Browse, and find jython.jar inside your Jython 2.5.1 installation. Commented Jul 4, 2016 at 22:48
  • @khredos, (cont'd), my confusion is it seems PyDev is just a toolkit? And I need to install Jython separately, correct? If so, would you mind to point me some guide how to install Jython on Mac OSX (which could be used together as PyDev Eclipse plug-in)? Thanks. Commented Jul 4, 2016 at 22:49
  • 2
    Your IDE isn't really PyCharm - it's Eclipse + PyDev. Any reason for mentioning / tagging the question with PyCharm? Commented Jul 5, 2016 at 6:13
  • 1
    I haven't used Jython - but PyCharm should support it just fine: jetbrains.com/help/pycharm/2016.1/configuring-python-sdk.html Commented Jul 5, 2016 at 6:55

1 Answer 1

3

Follow up on the comments above, yes if you are using pydev for Eclipse, then that's just the plugin that allows for writing python code with Eclipse. To install Jython, there are a number of guides out there, but it boils down to a two step process:

  1. Download and install Jython. The installation process will usually tell you where Jython is installed
  2. Next Configure your IDE to include the location of jython. As the JetBrains family of IDE's are very much the same, the way I added Jython to IntelliJ was File > Project Structure > SDK > + > Python SDK > Navigate to the Jython Binary

Also take some time to peruse the Jython Book.

Sign up to request clarification or add additional context in comments.

23 Comments

@LinMa Press that link on the first image that says "Please configure an interpreter before proceeding", this should give you the option to navigate to the install location of jython, then pycharm shall do the rest
@LinMa Did install jython? If so, where did the installer install jython?
@LinMa If you visit the command prompt and type jython and get an error message or something to the same effect, then jython is not installed. You can also type something like which jython or command -v jython. If nothing promising shows up, then you most likely don't have jython installed
@LinMa Yes there is, you might not have it on osx by default but if you tried the other methods and couldn't find jython, then just use homebrew to install it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.