Using NumPy and Cpython with Jython

It’s ironic, considering that Jython and Numeric (NumPy’s ancestor) were initiated by the same developer (Jim Hugunin, who then moved on to also initiate IronPython and now holds some kind of senior architect position at Microsoft, working on all kind of dynamic languages support for .NET and Silverlight), that there’s no really good way to … Read more

Cross-platform way to get PIDs by process name in python

You can use psutil (https://github.com/giampaolo/psutil), which works on Windows and UNIX: import psutil PROCNAME = “python.exe” for proc in psutil.process_iter(): if proc.name() == PROCNAME: print(proc) On my machine it prints: <psutil.Process(pid=3881, name=”python.exe”) at 140192133873040> EDIT 2017-04-27 – here’s a more advanced utility function which checks the name against processes’ name(), cmdline() and exe(): import os … Read more

Jython and python modules

You embed jython and you will use some Python-Modules somewere: if you want to set the path (sys.path) in your Java-Code : public void init() { interp = new PythonInterpreter(null, new PySystemState()); PySystemState sys = Py.getSystemState(); sys.path.append(new PyString(rootPath)); sys.path.append(new PyString(modulesDir)); } Py is in org.python.core. rootPath and modulesDir is where YOU want ! let rootPath … Read more

Distributing my Python scripts as JAR files with Jython?

The best current techniques for distributing your Python files in a jar are detailed in this article on Jython’s wiki: http://wiki.python.org/jython/JythonFaq/DistributingJythonScripts For your case, I think you would want to take the jython.jar file that you get when you install Jython and zip the Jython Lib directory into it, then zip your .py files in, … Read more

Using a java library from python

Sorry to ressurect the thread, but there was no accepted answer… You could also use Py4J. There is an example on the frontpage and lots of documentation, but essentially, you just call Java methods from your python code as if they were python methods: >>> from py4j.java_gateway import JavaGateway >>> gateway = JavaGateway() # connect … Read more

How can I install various Python libraries in Jython?

Some Python modules, like lxml, have required components in C. These won’t work in Jython. Most Python packages will work fine, and you can install them using the same tools as you use in CPython. This is described in Appendix A of Jython Book: To get setuptools, download ez_setup.py from http://peak.telecommunity.com/dist/ez_setup.py. Then, go to the … Read more

Calling Python in Java?

Jython: Python for the Java Platform – http://www.jython.org/index.html You can easily call python functions from Java code with Jython. That is as long as your python code itself runs under jython, i.e. doesn’t use some c-extensions that aren’t supported. If that works for you, it’s certainly the simplest solution you can get. Otherwise you can … Read more