Build status for all platforms: Commercial support:
By downloading these archives, you agree to the terms and conditions for accessing or otherwise using Python.
This directory contains the JavaCPP Presets module for:
- CPython 3.10.8 https://www.python.org/
Please refer to the parent README.md file for more detailed information about the JavaCPP Presets.
Java API documentation is available here:
∗ Call Py_Initialize(cachePackages())
instead of just Py_Initialize()
.
∗ To satisfy OpenSSL, we might need to set the SSL_CERT_FILE
environment variable to the full path of cacert.pem
extracted by default under ~/.javacpp/cache/
.
Here is a simple example of CPython ported to Java from this C source file:
We can use Maven 3 to download and install automatically all the class files as well as the native binaries. To run this sample code, after creating the pom.xml
and Simple.java
source files below, simply execute on the command line:
$ mvn compile exec:java
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.bytedeco.cpython</groupId>
<artifactId>simple</artifactId>
<version>1.5.8</version>
<properties>
<exec.mainClass>Simple</exec.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>cpython-platform</artifactId>
<version>3.10.8-1.5.8</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>.</sourceDirectory>
</build>
</project>
import org.bytedeco.javacpp.*;
import org.bytedeco.cpython.*;
import static org.bytedeco.cpython.global.python.*;
public class Simple {
public static void main(String[] args) throws Exception {
Pointer program = Py_DecodeLocale(Simple.class.getSimpleName(), null);
if (program == null) {
System.err.println("Fatal error: cannot decode class name");
System.exit(1);
}
Py_SetProgramName(program); /* optional but recommended */
Py_Initialize(cachePackages());
PyRun_SimpleString("from time import time,ctime\n"
+ "print('Today is', ctime(time()))\n");
if (Py_FinalizeEx() < 0) {
System.exit(120);
}
PyMem_RawFree(program);
System.exit(0);
}
}