JPype is available either as a pre-compiled binary for Anaconda, or may be built from source though various methods.
JPype can be installed as pre-compiled binary if you are using the Anaconda Python stack. Binaries are available for Linux, OSX, and windows on conda-forge.
Ensure you have installed Anaconda/Miniconda. Instructions can be found here.
Install from the conda-forge software channel:
conda install -c conda-forge jpype1
Installing from source requires:
JPype works CPython 3.5 or later. Both the runtime and the development package are required.
Either the Sun/Oracle JDK/JRE Variant or OpenJDK.
JPype source distribution includes a copy of the Java JNI header and precompiled Java code, thus the Java Development Kit (JDK) is not required. JPype has been tested with Java versions from Java 1.8 to Java 13.
A C++ compiler which matches the ABI used to build CPython.
(Optional) JPype contains sections of Java code. These sections are precompiled in the source distribution, but must be built when installing directly from the git repository.
Once these requirements have been met, one can use pip to build from either the source distribution or directly from the repository. Specific requirements from different achitectures are listed below.
Build using pip
JPype may be built and installed with one step using pip.
To install the latest JPype, use:
pip install JPype1
This will install JPype either from source or binary distribution, depending on your operating system and pip version.
To install from the current github master use:
pip install git+https://github.com/jpype-project/jpype.git
More details on installing from git can be found at Pip install. The git version does not include a prebuilt jar the JDK is required.
Build and install manually
JPype can be built entirely from source.
1. Get the JPype source
2. Build the source with desired options
Compile JPype using the included
python setup.py build
The setup script recognizes several arguments.
Force setup to recreate the jar from scratch.
Build a verison of JPype with full logging to the console. This can be used to diagnose tricky JNI issues.
After building, JPype can be tested using the test bench. The test bench requires JDK to build.
3. Test JPype with (optional):
python setup.py test
4. Install JPype with:
python setup.py install
If it fails…
Most failures happen when setup.py is unable to find the JDK home directory
which shouble be set in the enviroment variable
JAVA_HOME. If this
happens, preform the following steps:
Identify the location of your systems JDK installation and explicitly passing it to setup.py.
JAVA_HOME=/usr/lib/java/jdk1.8.0/ python setup.py install
If that setup.py still fails please create an Issue on github and post the relevant logs.
Platform Specific requirements
JPype is known to work on Linx, OSX, and Windows. To make it easier to those who have not built CPython modules before here are some helpful tips for different machines.
Debian/Ubuntu users will have to install
sudo apt-get install g++ python-dev python3-dev
CPython modules must be built with the same C++ compiler used to build Python. The tools listed below work for Python 3.5 to 3.8. Check with Python dev guide for the latest instructions.
Install your desired version of Python (3.5 or higher), e.g., Miniconda is a good choice for users not yet familiar with the language
For Python 3 series, Install either 2017 or 2019 Visual Studio. Microsoft Visual Studio 2019 Community Edition is known to work.
From the Python developer page:
When installing Visual Studio 2019, select the Python development workload and the optional Python native development tools component to obtain all of the necessary build tools. If you do not already have git installed, you can find git for Windows on the Individual components tab of the installer.
When building for windows you must use the Visual Studio developer command prompt.
On certain systems such as Windows 2016 Server, the JDK will not load properly despite JPype properly locating the JVM library. The work around for this issue is add the JRE bin directory to the system PATH. Apparently, the shared library requires dependencies which are located in the bin directory. If a JPype fails to load despite having the correct JAVA_HOME and system architecture, it may be this issue.
Java classes outside of a package (in the
<default>) cannot be imported.
Because of lack of JVM support, you cannot shutdown the JVM and then restart it. Nor can you start more than one copy of the JVM.
Mixing 64 bit Python with 32 bit Java and vice versa crashes on import of the jpype module.