0

I use the initialization of the following type:

if (!Py_IsInitialized()) {
        Py_Initialize();
        qInfo() << "INIT LIBs";
        PyRun_SimpleString("import sys");
        PyRun_SimpleString("import os");
        PyRun_SimpleString("import cv2");
        PyRun_SimpleString("import gc");
        PyRun_SimpleString("import numpy");
        PyRun_SimpleString("import tensorflow as tf");

        PyRun_SimpleString("from datetime import datetime");
        PyRun_SimpleString("from utils import label_map_util");
        PyRun_SimpleString("from utils import visualization_utils as vis_util");
    }

Next, I have frame processing with pyrun_simplestring. I know this is a bad way). But I need to know how I can clean the entire interpreter, including imported modules. I ask this because processing works fine for me until the moment of repeated interaction with the interpreter. If I start working with the translator again, the program will crash when interacting with numpy. Thanks for the help.

PyRun_SimpleString("image_expanded = numpy.expand_dims(image, axis = 0)")
Ackdari
  • 3,222
  • 1
  • 16
  • 33
Paul.S
  • 1
  • 2
  • In which do you program C or C++? – Ackdari May 14 '20 at 09:20
  • in C++ (15 characters) – Paul.S May 14 '20 at 09:26
  • 1
    Does this answer your question? [Py\_initialize / Py\_Finalize not working twice with numpy](https://stackoverflow.com/questions/7676314/py-initialize-py-finalize-not-working-twice-with-numpy) – DavidW May 14 '20 at 12:02
  • Also a duplicate of https://stackoverflow.com/questions/16779799/py-initialize-and-py-finalize-and-matplotlib, https://stackoverflow.com/questions/14843408/python-c-embedded-segmentation-fault, and https://stackoverflow.com/questions/59314230/python-c-api-crashes-on-import-numpy-when-initilizing-multiple-times – DavidW May 14 '20 at 12:03
  • Also been reported fairly extensively on the Numpy bug tracker eg https://github.com/numpy/numpy/issues/8097 – DavidW May 14 '20 at 12:04

0 Answers0