You need to "Add framework support" / Facets

As long as you already have python installed, just follow this.

Right-click the directory/module/project where you have your python scripts, right at the top you will see "Add framework Support..."

https://www.jetbrains.com/help/idea/adding-support-for-frameworks-and-technologies.html#disable-framework-auto-detection

Answer from Miguel Armenta on Stack Overflow
๐ŸŒ
Quora
quora.com โ€บ Can-you-use-Java-and-Python-for-the-same-projects
Can you use Java and Python for the same projects? - Quora
Yes โ€” Java and Python can be used together in the same project in multiple practical ways. Choice of integration pattern depends on goals (performance, libraries, developer velocity), system boundaries, and deployment constraints.
Discussions

Is there a way to use python and java in the same program? - Stack Overflow
I want to use both python and java in the same program. Since the print() function of python is better, but java's int variable; is more efficient. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Integration of Java and Python Code in One Eclipse Project - Stack Overflow
I am writing a compiler in Python using Eclipse with PyDev. I've come to a stage where I needed to write some code in Java. I'm wandering if there is a way of combining these into a single project, More on stackoverflow.com
๐ŸŒ stackoverflow.com
can both Java and Python be used at the same time on App Engine? - Stack Overflow
Alternatively you can use google app engine plugin for eclipse (if you are using) and deploy java project using run->run as-> Google Web Application and integrate python using Jython. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Java Python Integration - Stack Overflow
I have a Java app that needs to integrate with a 3rd party library. The library is written in Python, and I don't have any say over that. I'm trying to figure out the best way to integrate with it.... More on stackoverflow.com
๐ŸŒ stackoverflow.com

You need to "Add framework support" / Facets

As long as you already have python installed, just follow this.

Right-click the directory/module/project where you have your python scripts, right at the top you will see "Add framework Support..."

https://www.jetbrains.com/help/idea/adding-support-for-frameworks-and-technologies.html#disable-framework-auto-detection

Answer from Miguel Armenta on Stack Overflow
๐ŸŒ
Reddit
reddit.com โ€บ r/java โ€บ best way to combine python and java?
r/java on Reddit: Best way to combine Python and Java?
October 29, 2022 -

My project uses some packages that are available only in Python and heavily rely on C libraries. The project also greatly benefits from Java libraries and the JVM. What's the optimal way to call Python functions from Java?

I tried:

  1. Small web-services: overhead to serialize data, start and stop the services. Also debugging is harder and implementing each new function is now double the effort.

  2. Jpy: a library that runs an interpreter in the JVM. Spare the service start/stop, but: isn't really feasible for more than a single-liner, data translation between Java and Python is cumbersome, and I also encountered runtime segmentation fault errors.

Any other options?

The project is in the machine-learning domain, so involves exchanging large numeric arrays and text. In some cases the execution switches back and forth between the platforms.

๐ŸŒ
Jython
jython.org
Home | Jython
The Jython project provides implementations of Python in Java, providing to Python the benefits of running on the JVM and access to classes written in Java. The current release (a Jython 2.7.x) only supports Python 2 (sorry).
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ integrating-java-with-python
Integrating Java with Python - GeeksforGeeks
July 23, 2025 - Since we need to compile and execute the Java program first and then the Python program, we create a batch file (say, helloapp.bat) comprising these two tasks one after the other since compiling and running an eclipse program from the command line is a more complex job, we can convert the entire project to an executable jar file which can be used anywhere.
๐ŸŒ
LinkedIn
linkedin.com โ€บ pulse โ€บ integrating-python-java-guide-developers-myexamcloud-7g5bc
Integrating Python and Java: A Guide for Developers
December 26, 2023 - To use Py4J, you need to download and add the JAR files to your Java project's classpath. Then, you can start a Python process from within your Java application and use its functions and objects.
Find elsewhere
๐ŸŒ
Quora
quora.com โ€บ What-is-the-best-way-to-use-Python-and-Java-together
What is the best way to use Python and Java together? - Quora
Answer (1 of 6): I like to keep projects to a single language per execution environment to avoid the cost of context switching. Java, as a JVM language, can call code written in other languages; the bulk of my experience with this is calling Scala code from Java while working on a big Play! frame...
๐ŸŒ
Quora
quora.com โ€บ Can-Java-and-Python-be-used-together-in-any-interesting-projects-other-than-web-development-or-server-side-programming
Can Java and Python be used together in any interesting projects other than web development or server side programming? - Quora
A language that borrows ideas from both Python and Java (like Kotlin) can be better than both for a range of different projects, but a language that explicitly tries to fit in between them (like Groovy and Boo) is often just going to be not as good as Java, or not as good as Python, for any particular project. One last thing to consider is Jython. Jython is Python (still only 2.7, as of 2022, but thereโ€™s some ongoing work toward Python 3), running in the Java Virtual Machine. Its syntax and semantics are the same as any other Python, but it has direct native access to Java classes, including the entire Java standard library on top of the Python one, and it implicitly treats Java string and primitive value types as their equivalent Python types.
๐ŸŒ
Devmio
devm.io โ€บ python โ€บ integrating-python-with-java-170663
Integrating Python with Java
April 21, 2020 - Python is an object-oriented scripting language, which automatically makes it a good pair for Java. But when combined with a Python interpreter written entirely in Java, like Jython, you could do things like write entire applets in Python.
๐ŸŒ
JetBrains
intellij-support.jetbrains.com โ€บ hc โ€บ en-us โ€บ community โ€บ posts โ€บ 22315323427730-Setting-Up-Python-Django-and-Java-Spring-in-One-Project-in-IntelliJ-IDEA
Setting Up Python (Django) and Java (Spring) in One Project in IntelliJ IDEA โ€“ IDEs Support (IntelliJ Platform) | JetBrains
October 30, 2024 - Hereโ€™s a detailed description of the steps Iโ€™ve already taken and the issues Iโ€™m facing:Install Python from https://www.python.org/downloads/ (select "Add Python to PATH"); check if the path to python.exe is added to environment variables (run python --version in the IntelliJ IDEA terminal); if not, add it manually: Control Panel โ†’ System โ†’ Advanced System Settings โ†’ Environment Variables โ†’ System Variables โ†’ Path โ†’ New โ†’ enter path to python.exe โ†’ OK โ†’ restart PC; install the Python plugin in IntelliJ IDEA (latest JetBrains version) โ†’ restart IDE; update the project
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ how to call python from java
How to Call Python From Java | Baeldung
August 27, 2025 - When we run this code a PyException is thrown and weโ€™ll see the same error as if we were working with native Python: Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named syds ... As PythonIntepreter implements AutoCloseable, itโ€™s good practice to use try-with-resources when working with this class ยท The PythonInterpreter class name does not imply that our Python code is interpreted. Python programs in Jython are run by the JVM and therefore compiled to Java bytecode before execution
Top answer
1 of 12
38

Why not use Jython? The only downside I can immediately think of is if your library uses CPython native extensions.

EDIT: If you can use Jython now but think you may have problems with a later version of the library, I suggest you try to isolate the library from your app (e.g. some sort of adapter interface). Go with the simplest thing that works for the moment, then consider JNI/CPython/etc if and when you ever need to. There's little to be gained by going the (painful) JNI route unless you really have to.

2 of 12
21

Frankly most ways to somehow run Python directly from within JVM don't work. They are either not-quite-compatible (new release of your third party library can use python 2.6 features and will not work with Jython 2.5) or hacky (it will break with cryptic JVM stacktrace not really leading to solution).

My preferred way to integrate the two would use RPC. XML RPC is not a bad choice here, if you have moderate amounts of data. It is pretty well supported โ€” Python has it in its standard library. Java libraries are also easy to find. Now depending on your setup either Java or Python part would be a server accepting connection from other language.

A less popular but worth considering alternative way to do RPCs is Google protobuffers, which have 2/3 of support for nice rpc. You just need to provide your transport layer. Not that much work and the convenience of writing is reasonable.

Another option is to write a C wrapper around that pieces of Python functionality that you need to expose to Java and use it via JVM native plugins. You can ease the pain by going with SWIG SWIG.

Essentially in your case it works like that:

  1. Create a SWIG interface for all method calls from Java to C++.
  2. Create C/C++ code that will receive your calls and internally call python interpreter with right params.
  3. Convert response you get from python and send it via swig back to your Java code.

This solution is fairly complex, a bit of an overkill in most cases. Still it is worth doing if you (for some reason) cannot afford RPCs. RPC still would be my preferred choice, though.

๐ŸŒ
DEV Community
dev.to โ€บ alli โ€บ what-happened-when-i-learned-java-and-python-at-the-same-time-1haa
What Happened When I Learned Java and Python at the Same Time - DEV Community
August 13, 2019 - That's how I ended up with two different programming books learning two different languages at the same time. And I was still coding primarily in JavaScript for my regular job. What was I thinking? I have no idea. Currently I've finished the first six chapters of the Java book and the Python book only has a few chapters left.
๐ŸŒ
Medium
medium.com โ€บ @chamlinid โ€บ integrate-java-and-python-code-bases-1c4819fe19da
Integrate Java and Python code bases | by Chamlini Dayathilake | Medium
February 14, 2025 - The method used for integration: Using ProcessBuilder in Java. (java.lang.ProcessBuilder) One thing that you need to do when using this method is, simplify parameter values and returns as much as you can. [Do not use complex objects, rather define them as primitives or Strings]. The base story is trying to use powerful machine learning libraries from Python inside a Java program.
๐ŸŒ
Quora
quora.com โ€บ Is-there-a-way-to-use-both-Python-and-Java-together-in-one-project-How-can-I-use-them-together-and-which-of-them-for-which-purposes
Is there a way to use both Python and Java together in one project? How can I use them together and which of them for which purposes? - Quora
Answer: Yes possible to make project which have some code written in python and some in Java.. but these things generally done with pre-existing project which already written using one language and new functionality or upgradation is going .
๐ŸŒ
Py4j
py4j.org
Welcome to Py4J โ€” Py4J
This is the Java program that was executing at the same time (no code was generated and no tool was required to run these programs). The AdditionApplication app instance is the gateway.entry_point in the previous code snippet. Note that the Java program must be started before executing the Python code above.