Compile orekit python wrapper for python module

Hi all,

I followed this url Manual Installation of Python Wrapper · Wiki · Orekit Labs / Orekit Python Wrapper · GitLab for compiling orekit wraper.

I have successfully compiled with version 11.1.

When I want to use the orekit python wrapper version 11.3, I failed to compile it.

I downloaded the source from:

Below I the procedure I use to compile:

Source Structure

/tmp/orekit-python-wrapper
build
build.sh
hipparchus-core-2.3.jar
hipparchus-filtering-2.3.jar
hipparchus-fitting-2.3.jar
hipparchus-geometry-2.3.jar
hipparchus-ode-2.3.jar
hipparchus-optim-2.3.jar
hipparchus-stat-2.3.jar
orekit-11.3.jar
pyhelpers.py
rugged-3.0.jar

Build Script

#!/bin/bash
PKG_VERSION=11.3
OREKIT_VERSION=11.3
HIPPARCHUS_VERSION=2.3
RUGGED_VERSION=3.0
 
PREFIX=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-11.el8.x86_64
export JCC_JDK="${PREFIX}"
export JCC_ARGSEP=";"
export JCC_LFLAGS="-v;-Wl,-v;-L${PREFIX}/jre/lib/amd64;-ljava;-L${PREFIX}/jre/lib/amd64/server;-ljvm;-lverify;-Wl,-rpath=${PREFIX}/jre/lib/amd64:${PREFIX}/jre/lib/amd64/server"
export JCC_INCLUDES="${PREFIX}/include;${PREFIX}/include/linux"
export JCC_JAVAC=${PREFIX}/bin/javac
export JCC_CFLAGS="-v;-fno-strict-aliasing;-Wno-write-strings;-D__STDC_FORMAT_MACROS"
export JCC_DEBUG_CFLAGS="-O0;-g;-DDEBUG"
export JCC_JAVADOC="javadoc"
printenv
 
python3.8 -m jcc \
--use_full_names \
--python orekit \
--version ${PKG_VERSION} \
--jar $SRC_DIR/orekit-${OREKIT_VERSION}.jar \
--jar $SRC_DIR/hipparchus-core-${HIPPARCHUS_VERSION}.jar \
--jar $SRC_DIR/hipparchus-filtering-${HIPPARCHUS_VERSION}.jar \
--jar $SRC_DIR/hipparchus-fitting-${HIPPARCHUS_VERSION}.jar \
--jar $SRC_DIR/hipparchus-geometry-${HIPPARCHUS_VERSION}.jar \
--jar $SRC_DIR/hipparchus-ode-${HIPPARCHUS_VERSION}.jar \
--jar $SRC_DIR/hipparchus-optim-${HIPPARCHUS_VERSION}.jar \
--jar $SRC_DIR/hipparchus-stat-${HIPPARCHUS_VERSION}.jar \
--jar $SRC_DIR/rugged-${RUGGED_VERSION}.jar \
--package java.io \
--package java.util \
--package java.text \
--package org.orekit \
java.io.BufferedReader \
java.io.FileInputStream \
java.io.FileOutputStream \
java.io.InputStream \
java.io.InputStreamReader \
java.io.ObjectInputStream \
java.io.ObjectOutputStream \
java.io.PrintStream \
java.io.StringReader \
java.io.StringWriter \
java.lang.System \
java.text.DecimalFormat \
java.text.DecimalFormatSymbols \
java.util.ArrayList \
java.util.Arrays \
java.util.Collection \
java.util.Collections \
java.util.Date \
java.util.HashMap \
java.util.HashSet \
java.util.List \
java.util.Locale \
java.util.Map \
java.util.Set \
java.util.TreeSet \
java.util.stream.Collectors \
java.util.stream.Stream \
java.util.stream.DoubleStream \
java.util.function.LongConsumer \
java.util.function.IntConsumer \
java.util.function.DoubleConsumer \
--module $SRC_DIR/pyhelpers.py \
--reserved INFINITE \
--reserved ERROR \
--reserved OVERFLOW \
--reserved NO_DATA \
--reserved NAN \
--reserved min \
--reserved max \
--reserved mean \
--reserved SNAN \
--classpath $PREFIX/lib/tools.jar \
--files 81 \
--build \
--install

Prepare to compile

[root@localhost tmp]# virtualenv env
created virtual environment CPython3.8.12.final.0-64 in 387ms
  creator CPython3Posix(dest=/tmp/env, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
    added seed packages: pip==22.0.4, setuptools==62.1.0, wheel==0.37.1
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
[root@localhost tmp]# source env/bin/activate
(env) [root@localhost tmp]# export JCC_JDK=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-11.el8.x86_64
(env) [root@localhost tmp]# python3.8 -m pip install jcc --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org
Requirement already satisfied: jcc in ./env/lib64/python3.8/site-packages (3.13)
WARNING: You are using pip version 22.0.4; however, version 22.3.1 is available.
You should consider upgrading via the '/tmp/env/bin/python3.8 -m pip install --upgrade pip' command.
(env) [root@localhost tmp]# export SRC_DIR=/tmp/orekit-python-wrapper/
(env) [root@localhost tmp]# cd orekit-python-wrapper/
(env) [root@localhost orekit-python-wrapper]# ./build.sh

The errors appear:

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPYTHON -DJCC_VER=\"3.13\" -D_java_generics -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-11.el8.x86_64/include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-11.el8.x86_64/include/linux -Ibuild/_orekit -I/usr/local/python310/lib/python3.10/site-packages/jcc/sources -I/usr/local/python310/include/python3.10 -c build/_orekit/__wrap67__.cpp -o build/temp.linux-x86_64-cpython-310/build/_orekit/__wrap67__.o -fno-strict-aliasing -Wno-write-strings
build/_orekit/__wrap67__.cpp:611:147: error: wrong number of template arguments (1, should be 2)
         { Py_tp_iternext, (void *) ((PyObject *(*)(::java::util::t_Iterator *)) get_iterator_next< ::java::util::t_Iterator,t_JArrayWrapper< jint > >) },
                                                                                                                                                   ^
In file included from build/_orekit/__wrap67__.cpp:9:
/usr/local/python310/lib/python3.10/site-packages/jcc/sources/JArray.h:1823:40: note: provided for âtemplate<class T, class U> class t_JArrayWrapperâ
 template<typename T, typename U> class t_JArrayWrapper {
                                        ^~~~~~~~~~~~~~~
build/_orekit/__wrap67__.cpp:611:81: error: insufficient contextual information to determine type
         { Py_tp_iternext, (void *) ((PyObject *(*)(::java::util::t_Iterator *)) get_iterator_next< ::java::util::t_Iterator,t_JArrayWrapper< jint > >) },
                                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: command '/usr/bin/gcc' failed with exit code 1

Compiler with :
Java 1.8
gcc version 8.5.0 20210514 (Red Hat 8.5.0-12) (GCC)
python 3.8

Please, would you mind give me some suggestions?

Many thanks
Sotheavut

Hi Sotheavut,

It it can be quite tricky to get it to build in some configurations, that’s why recommend using the prebuilt ones in conda.

It looks like you are not using the latest build script (orekit-feedstock/build.sh at main · conda-forge/orekit-feedstock · GitHub), there was an issue with RosenNumberPartitionIterator which could be what you are seeing.

You would otherwise need to get into the generated code and try to figure out which java function it is wrapping, one way to start is to exclude it temprary to try to get the rest built. Different compilers prefer different splitting, you can try to split it in less or more parts (–file directive).

Regards
Petrus

Thank you Petrus,

I just updated the build script according to the URL you provided, and I compiled it successfully.

Kind regards
Sotheavut

Thank you Petrus and Sotheavut for this up-to-date summary of the building procedure for Orekit Python wrapper !
I’ve tried to replicate it with same versions and script as Sotheavut (orekit python artefacts 11.3.0, java 1.8, python 3.8 and gcc 8.5 and the build script from the URL provided by Petrus).
Unfortunately, I obtain the following error

While loading org/orekit/compiler/plugin/DefaultDataContextPlugin$AnnotationTreeScanner
Traceback (most recent call last):
  File "/usr/lib64/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib64/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib64/python3.8/site-packages/jcc/__main__.py", line 112, in <module>
    cpp.jcc(sys.argv)
  File "/usr/local/lib64/python3.8/site-packages/jcc/cpp.py", line 665, in jcc
    cls = findClass(className.replace('.', '/'))
  File "/usr/local/lib64/python3.8/site-packages/jcc/cpp.py", line 51, in findClass
    cls = _findClass(className)
jcc.cpp.JavaError: java.lang.NoClassDefFoundError: com/sun/source/util/TreeScanner
Java stacktrace:
java.lang.NoClassDefFoundError: com/sun/source/util/TreeScanner
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
Caused by: java.lang.ClassNotFoundException: com.sun.source.util.TreeScanner
        at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)

Does it ring a bell ? I’m a new comer to Java/Orekit world so it may be something stupid…

Hello,
My problem is solved ! I made a mistake in the initialization of the variable PREFIX=“/usr/lib/jvm/java-1.8.0-openjdk” of the script build.sh. Consequently, tools.jar was missing…
Thanks for the hint on tools.jar, it was of great help.
Now ready to discover Orekit :slight_smile:

Great you managed to solve it!