Java Embedded Python (JEP)
Java Embedded Python (JEP)
provides access to a locally-installed Python interpreter and
makes it very easy to pass values from Java to Python,
execute Python operations, functions, and objects, and retrieve
Python data suitably translated into Java (e.g.
a Python dictionary becomes a Java Map, and a NumPy array
is treated as a Java array).
The biggest drawback of using JEP is that its installation
on MS Windows requires Visual
Studio Build Tools (a 9 GB download) to
compile the necessary C++ glue code which links JEP
to Python. However, the JEP developers have gone
to some trouble to document the required steps with specific
installation guides for
Linux,
OSX, and
MS
Windows.
I've also included a few additional tips that I
picked up when installing JEP on MS Windows 10. They're
listed in the "Other Downloads and Links" section at the
bottom of this page.
My Examples
Most of these examples come with a
corresponding Python script which can be executed
in Python directly. That's a good strategy for testing
that you have Python, and all the necessary third-party
modules, correctly installed. It's also useful to compare
the JEP version of code with similar Python.
Other Downloads and Links
- Batch files to compile and run my code:
compile.bat and
run.bat
- All the examples in one zipped file
(20 KB)
- The excellent JEP
documentation
- The JEP
API documentation.
- My zipped copy of the
JEP libraries, jep-4.1.1.jar and
jep.dll, which will
PROBABLY NOT WORK (224 KB).
These libraries are intimately connected to the
version of Python you have installed, and the OS.
I've included them only as placeholders; you'll need to replace
them with versions that you have compiled
on your machine (see below).
However, still place the unzipped libs folder
in the same directory as the examples and batch files.
- The JEP installation details for MS Windows can be found
here.
I'd like to add a few extra tips:
- Before you install JEP, make sure that Python
and NumPy are working correctly standalone. In
particular, you should be able to execute a script by
typing python script in a terminal window.
- There must be a JAVA_HOME
environment variable set to point to your JDK.
- Install "Build Tools for
Visual Studio 2022", which can be accessed at the bottom
of the
Visual Studio page. Open the tab
marked "Tools for Visual Studio" and click on the relevant
"Download" button. After downloading the installer, start it up
and it'll open a window offering you
numerous installation combinations – go for the
"Desktop development with C++" option. The 10 GB download
can be shrunk by deselecting the last 3 sub-options
(C++ CMake, Testing tools, and C++ AddressSanitizer).
- At last (!), you can install JEP with
pip install jep. This will
build and install the necessary JEP JARs and DLLs.
- Now its time to replace the two library files,
jep-4.1.1.jar and
jep.dll in my
libs/ folder by copies of your versions. On my test machines
they're in Python 3.8's site-packages/ folder,
which has a path something like
C:\Users\HP\AppData\Local\Programs\Python\Python38\Lib\site-packages\jep-4.1.1-py3.8-win-amd64.egg\jep. Copy
them over to the
libs/ folder in jep-examples/,
deleting my copies in the process.
- My examples use a number of third-party Python libraries,
which you'll have to install in Python (using pip).
These are NumPy,
Matplotlib,
Sympy, and
Art.
Dr. Andrew Davison
E-mail: ad@coe.psu.ac.th
Back to the third-party libraries page