Unable to import modules such as numpy, pandas etc. while embedding python code in C. I am using Jetson TX2 NX as development board with ubuntu18.04, deepstream sdk 6.0.1 and Jetpack 4.6.2. I have python 3.6.9 (python3 -V). Numpy is installed in /usr/lib/python3/dist-packages and also I have provided python library path in Makefile.
And below is the deepstream_app.c embedded code snippet , Below snippet is inserted in function **write_kitti_track_output()** in the for loop, which repeats after every frame.
path - path where the python file is located
calculate_values - function in python file
f_num, l,w,t,h - parameters
Unable to import modules such as numpy, pandas etc. while embedding python code in C. I am using Jetson TX2 NX as development board with ubuntu18.04, deepstream sdk 6.0.1 and Jetpack 4.6.2. I have python 3.6.9 (python3 -V). Numpy is installed in /usr/lib/python3/dist-packages and also I have provided python library path in Makefile.
Below is the snippet of Makefile below.
CUDA_VER?= ifeq ($(CUDA_VER),) $(error "CUDA_VER is not set") endif APP:= deepstream-app TARGET_DEVICE = $(shell gcc -dumpmachine | cut -f1 -d -) NVDS_VERSION:=6.0 LIB_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/lib/ APP_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/bin/ ifeq ($(TARGET_DEVICE),aarch64) CFLAGS:= -DPLATFORM_TEGRA endif SRCS:= $(wildcard .c) SRCS+= $(wildcard ../../apps-common/src/.c) INCS:= $(wildcard *.h) PKGS:= gstreamer-1.0 gstreamer-video-1.0 x11 json-glib-1.0 OBJS:= $(SRCS:.c=.o) CFLAGS:= -I./ -I../../apps-common/includes \ -I../../../includes -DDS_VERSION_MINOR=1 -DDS_VERSION_MAJOR=5 \ -I /usr/local/cuda-$(CUDA_VER)/include CFLAGS+= -I/usr/include/python3.6m -I/usr/include/python3.6m LDFLAGS:= -L/usr/lib/python3.6/config-3.6m-aarch64-linux-gnu -L/usr/lib -lpython3.6m \ -L/usr/lib/python3.6/dist-packages/cv2/python-3.6/ \ -L$(LIB_INSTALL_DIR)
PKG_CONFIG:= /usr/bin/pkg-config CFLAGS+=-I$(PKG_CONFIG --cflags cv2) LIBS:= -L/usr/local/cuda-$(CUDA_VER)/lib64/ -lcudart -lpython3.6m \ LIBS+= -L$(LIB_INSTALL_DIR) -lnvdsgst_meta -lnvds_meta -lnvdsgst_helper \ -lnvdsgst_smartrecord -lnvds_utils -lnvds_msgbroker -lm \ -lcuda -lgstrtspserver-1.0 -ldl -Wl,-rpath,$(LIB_INSTALL_DIR) LIBS+= -lpython3.6m CFLAGS+= $(shell pkg-config --cflags $(PKGS)) LIBS+= $(shell pkg-config --libs $(PKGS)) all: $(APP) %.o: %.c $(INCS) Makefile $(CC) -c -o $@ $(CFLAGS) $< $(APP): $(OBJS) Makefile $(CC) -o $(APP) $(OBJS) $(LIBS) install: $(APP) cp -rv $(APP) $(APP_INSTALL_DIR) clean: rm -rf $(OBJS) $(APP)
And below is the deepstream_app.c embedded code snippet , Below snippet is inserted in function **write_kitti_track_output()** in the for loop, which repeats after every frame.
path - path where the python file is located
calculate_values - function in python file
f_num, l,w,t,h - parameters
Py_Initialize() char path = "/home/jetsontx2/script"; wchar_t wpath = charToWChar(path); PySys_SetPath(wpath); free(wpath); PyObject module = PyImport_ImportModule("pyth"); PyObject function = PyObject_GetAttrString(module, "calculate_values"); PyObject args = PyTuple_New(5); PyTuple_SetItem(args, 0, Py_BuildValue("i", f_num)); PyTuple_SetItem(args, 1, Py_BuildValue("i", l)); PyTuple_SetItem(args, 2, Py_BuildValue("i", t)); PyTuple_SetItem(args, 3, Py_BuildValue("i", w)); PyTuple_SetItem(args, 4, Py_BuildValue("i", h)); PyObject result = PyObject_CallObject(function, args); int value1, value2; if (PyArg_ParseTuple(result, "ii", &value1, &value2)) { printf("(l + t): %d\n",value1); printf("(w + h): %d\n", value2); } else { printf("Failed to parse the result tuple.\n"); } Py_DECREF(module); Py_DECREF(function); Py_DECREF(args); Py_DECREF(result);
Py_Finalize()
I was able to run the same file using gcc but
I am not able to run in deepstream using make.