title: How to call a python file using Tensorflow library in C++ environment?
body: <p><a href="https://i.stack.imgur.com/9GcIs.png" rel="nofollow noreferrer">When I tried to call a python file using Tensorflow library in C++ environment, I got a problem like this. I have no idea how to solve it.</a></p>
  
  <p>This is my C++ code.</p>
  
  <pre><code>#include &lt;Python.h&gt;
  #include &lt;iostream&gt;
  
  
  int main(int argc, wchar_t** argv)
  {
      const char* picpath ="/home/senius/Pictures/zys.jpg";
      Py_Initialize();
      //PySys_SetArgv(argc, argv);
      //PyRun_SimpleString("import sys\nprint sys.argv");
      if ( !Py_IsInitialized() ) {
          return -1;
      }
      PyRun_SimpleString("import sys");
      PyRun_SimpleString("sys.path.append('/home/senius/Python/Ctensor/')");
      PyObject* pMod = NULL;
      PyObject* pFunc = NULL;
      PyObject* pParm = NULL;
      PyObject* pRetVal = NULL;
      int iRetVal = -999;
      const char* modulName="classify";    //这个是被调用的py文件模块名字
      pMod = PyImport_ImportModule(modulName);
      if(!pMod)
      {
          std::cout&lt;&lt;"Import module failed!";
          PyErr_Print();
          return -1;
      }
      const char* funcName="evaluate";  //这是此py文件模块中被调用的函数名字
      pFunc = PyObject_GetAttrString(pMod, funcName);
      if(!pFunc)
      {
          std::cout&lt;&lt;"Import function failed!";
          return -2;
      }
     pParm = PyTuple_New(1);
     PyTuple_SetItem(pParm, 0, Py_BuildValue("s",picpath));//传入的参数，是图片的路径
     pRetVal = PyEval_CallObject(pFunc, pParm);//这里开始执行py脚本
     PyArg_Parse(pRetVal, "i", &amp;iRetVal);//py脚本返回值给iRetVal
     //PyErr_Print();
     std::cout&lt;&lt;iRetVal;
     return iRetVal;
  }
  </code></pre>
  
  <p>This is my python code.</p>
  
  <pre><code>from PIL import Image
  import numpy as np
  import sys
  import tensorflow as tf
  
  def evaluate(pic):
      if not hasattr(sys, 'argv'):
          sys.argv  =  ['']
      image = Image.open(pic)
      image = image.resize([256, 256])
      image_array = np.array(image)
      max_index = np.argmax([1, 2, 32])
      return max_index
  </code></pre>
  
  <p>Once I import Tensorflow in python code, there will be a error. If I don't import Tensorflow, error disappears.</p>
  
  <p>Error information is as followed.</p>
  
  <pre><code>Import module failed!Traceback (most recent call last):
  File "/home/senius/Python/Ctensor/classify.py", line 4, in &lt;module&gt;
    import tensorflow as tf
  File "/home/senius/anaconda3/lib/python3.6/site-    packages/tensorflow/__init__.py", line 24, in &lt;module&gt;
    from tensorflow.python import *
  File "/home/senius/anaconda3/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 63, in &lt;module&gt;
    from tensorflow.python.framework.framework_lib import *
  File "/home/senius/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/framework_lib.py", line 76, in &lt;module&gt;
    from tensorflow.python.framework.ops import Graph
  File "/home/senius/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 37, in &lt;module&gt;
    from tensorflow.python.eager import context
  File "/home/senius/anaconda3/lib/python3.6/site-packages/tensorflow/python/eager/context.py", line 28, in &lt;module&gt;
    from tensorflow.python.platform import app
  File "/home/senius/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 23, in &lt;module&gt;
    from tensorflow.python.platform import flags
  File "/home/senius/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/flags.py", line 26, in &lt;module&gt;
    _global_parser = _argparse.ArgumentParser()
  File "/home/senius/anaconda3/lib/python3.6/argparse.py", line 1622, in __init__
  prog = _os.path.basename(_sys.argv[0])
  AttributeError: module 'sys' has no attribute 'argv'
  </code></pre>