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 OverflowYou 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
What worked better for me was to go to
Project Structure > Project Settings > Modules
then select my module, on the right-hand side pane choose Dependencies,
and from there, I set the Python SDK via the Module SDK: drop down

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:
-
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.
-
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.
Is there a way to use python and java in the same program? - Stack Overflow
Integration of Java and Python Code in One Eclipse Project - Stack Overflow
can both Java and Python be used at the same time on App Engine? - Stack Overflow
For what reason should a Python coder also learn Java, and how can you use Python and Java together?
Videos
If I'm interpreting correctly, you want to use to use both interchangeably in the same file, so you'd end up with code like:
def main():
int x = 5;
print(x)
This is impossible, because there would be ambiguity when trying to interpret code if you allowed constructs from both languages. For example, "X" + 1 is allowed in java, and would give you the string "X1". In python, it would give you an error because you can't add an int to a string. This would mean that there would be no way to know what your code should do because it's runnable in both languages.
This is a problem that all of us face, where we like some parts of some languages and other parts of other languages. The solution is pretty much just to decide what's most important, choose one language based on that, and then put up with the parts you don't like.
You can use Jython, which is a Python implementation based on the JVM/JDK. This allows calling between Java and Python code in both directions.
You can keep things in separate projects without having to copy the .class files to the Python project provided that you make that project a PyDev project and add the place that contains the .class files (i.e.: bin folder) as a source folder in the PyDev configuration (and reference that project from your Python project).
Take a look at "Project reference for Jython users" (in the end of http://pydev.org/manual_101_project_conf2.html).
I think you could also do what you asked in your question: create a java project, set it as a PyDev project too (right click that project > pydev > set as pydev project) and configure the PyDev project properties setting the PYTHONPATH to the place where you have your Python files and add another entry to the bin folder (i.e.: where the .class files exist). Not sure if it'd be better to keep those as 2 separated projects though.
I think Jython would be ideal here, as the Python code essentially gets translated to Java bytecode and run on the Java virtual machine, making it easy to communicate between the two. Also, pydev itself integrates well with Jython.
I had exactly the same need a week ago or so, and found a solution: Can Java and Python coexist in the same app?
EDIT: I accepted the first answer, but it happens that the second answer gave me best results, as i explain on the comments there.
EDIT 2: Well, it might not be exactly the same need, as i only needed to access the same datastore. If you want Java and Python running side-by-side, then i think Jython would be the best solution, as larsmans mentioned above.
Use py4j to communicate java and python and you need only secret id or user id to connect with google app engine .But if you need standalone application for both then you will need yaml file and their configuration.
from py4j.java_gateway import JavaGateway
gateway = JavaGateway() # connect to the JVM
gateway.jvm.java.lang.System.out.println('Hello World!')
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. https://developers.google.com/eclipse/docs/creating_new_webapp?hl=en
Nebulous and strange question, sorry.
I am a machine learning engineer. 100% of my job is done in Python (and shell, of course). So if I never learn another language, I’ll probably be fine for the foreseeable future.
But I want to learn other languages, both just for fun and because I think it will make me a better coder overall. For some reason Java calls me. But I can’t really explain why, nor could I tell you what I’d use Java for once I learned it.
So for the Pythonistas among us who also know Java, how has Java enriched your life? What do you use it for? How (and how often) do you integrate Python and Java within the same project?
Basically, convince me why what I'm already planning to do (=learn Java) would be not just enriching, but actually useful. Bonus points if you have anything to add here that’s specifically relevant to machine learning, since that is my path.
I'm aware of the Jython project, but it looks like this represents a way to use Java and its libraries from within Python, rather than the other way round - am I wrong about this?
Yes, you are wrong. You can either call a command line interpreter to run python code using Jyton or use python code from Java. In the past there was also a python-to-Java compiler, but it got discontinued with Jython 2.2
I would write a Python module to handle the text and language processing, and then build a small bridge in jython that your java program can interact with. The jython bridge will be a very simple one, that's really only responsible for forwarding calls to the python module, and return the answer from the python module to the java module. Jython is really easy to use, and setup shouldn't take you more than 15 minutes.
Best of luck!