title: Unable to PyImport_Import modules which imports modules
body: <p>This is the first time I post a question here, so I hope, I am doing it correctly otherwise please let me know.</p>
  
  <p>I am trying to make a wrapper with c++ and call a python module. I am able to call a simple python module, however, as soon as I include a python module, which imports modules, I get a segmentation fault.</p>
  
  <p>I import the code as, where I use a helper class:</p>
  
  <pre><code>setenv("PYTHONPATH", "./AugmentedAutoencoder/auto_pose/test", 0);
  
      CPyInstance hInstance;  
      if(!Py_IsInitialized()){
          std::cout &lt;&lt; "unable to init Py" &lt;&lt; std::endl;
      }
      else{
          CPyObject pName = PyUnicode_FromString("aae_webcam");
  
          CPyObject pModule = PyImport_Import(pName);
  
  
  
  
          if(pModule)
          {
              std::cout &lt;&lt; "Module imported.. " &lt;&lt; std::endl;
  
          }
          else
          {
              printf("ERROR: Module not imported \n");
              PyErr_Print();
          }
      }
  </code></pre>
  
  <p>The beginning of the python module imported is something like:</p>
  
  <pre><code>import cv2
  import argparse
  import tensorflow as tf
  import numpy as np
  import os
  import configparser
  
  from auto_pose.ae import factory
  from auto_pose.ae import utils as u
  from webcam_video_stream import WebcamVideoStream
  
  parser = argparse.ArgumentParser()
  parser.add_argument("experiment_name")
  arguments = parser.parse_args()
  
  full_name = arguments.experiment_name.split('/')
  
  experiment_name = full_name.pop()
  experiment_group = full_name.pop() if len(full_name) &gt; 0 else ''
  </code></pre>
  
  <p>I've tried to look for the answer online, however, unsuccessful. Thus I hope you are able to come to my aid.</p>
  
  <p><strong>Edit:</strong>
  The CPyObject is an instance of a class:</p>
  
  <pre><code>class CPyInstance
  {
  public:
      CPyInstance()
      {
          Py_Initialize();
      }
  
      ~CPyInstance()
      {
          Py_Finalize();
      }
  };
  
  
  class CPyObject
  {
  private:
      PyObject *p;
  public:
      CPyObject() : p(NULL)
      {}
  
      CPyObject(PyObject* _p) : p(_p)
      {}
  
  
      ~CPyObject()
      {
          Release();
      }
  
      PyObject* getObject()
      {
          return p;
      }
  
      PyObject* setObject(PyObject* _p)
      {
          return (p=_p);
      }
  
      PyObject* AddRef()
      {
          if(p)
          {
              Py_INCREF(p);
          }
          return p;
      }
  
      void Release()
      {
          if(p)
          {
              Py_DECREF(p);
          }
  
          p= NULL;
      }
  
      PyObject* operator -&gt;()
      {
          return p;
      }
  
      bool is()
      {
          return p ? true : false;
      }
  
      operator PyObject*()
      {
          return p;
      }
  
      PyObject* operator = (PyObject* pp)
      {
          p = pp;
          return p;
      }
  
      operator bool()
      {
          return p ? true : false;
      }
  };
  </code></pre>