title: Fatal Python error: failed to get random numbers to initialize Python
body: <p>Fatal Python error: failed to get random numbers to initialize Python</p>
  
  <p>Environment windows 10, VSC 15</p>
  
  <p>Using CreateProcessA winapi and passing lpenvironment variable to run python with scripts.
  when lpenvironment is passed null, it works fine.
  If I set environment variable PATH and PYTHONPATH = "paths", and pass that LPSTR(env.c_Str()), it throws above error on running.
  The python version is 3.5.6</p>
  
  <p>Any help?</p>
  
  <hr>
  
  <p>Some more details.</p>
  
  <ol>
  <li>I run child process python.exe "C:\Program Files\endpoint\Python_ML\mlprocessor_server.py" using CreateProcessA WINAPI.</li>
  <li>I want to run child process with two environmental variables "PYTHONPATH" and "PATH".
  PYTHONPATH="C:\Program Files\endpoint\Python";"C:\Program Files\endpoint\Python\Scripts";"C:\Program Files\endpoint\Python\include";"C:\Program Files\endpoint\Python\Lib";"C:\Program Files\endpoint\Python\libs";"C:\Program Files\endpoint\Python\Lib\site-packages";"C:\Program Files\endpoint\Python_ML"
  PATH="C:\Program Files\endpoint\Python";"C:\Program Files\endpoint\Python\Lib";"C:\Program Files\endpoint\Python\Scripts";"C:\Program Files\endpoint\Python\libs"</li>
  </ol>
  
  <p>For some reason, the 7th parameter in CreateProcessA fails, the python.exe runs successfully if it is null, or else it prints "Fatal Python error: failed to get random numbers to initialize Python".</p>
  
  <h2>The way I set the parameter as follows...</h2>
  
  <p>std::string Base = Configuration::getBasePath();</p>
  
  <pre><code>std::string environPython = Base;
  environPython.append("\\Python;");
  environPython.append(Base);
  environPython.append("\\Python\\Scripts;");
  environPython.append(Base);
  environPython.append("\\Python\\include;");
  environPython.append(Base);
  environPython.append("\\Python\\Lib;");
  environPython.append(Base);
  environPython.append("\\Python\\libs;");
  environPython.append(Base);
  environPython.append("\\Python\\Lib\\site-packages;");
  environPython.append(Base);
  environPython.append("\\Python\\_ML;");
  environPython.push_back('\0');
  
  
  std::string environPath = Base;
  environPath.append("\\Python;");
  environPath.append(Base);
  environPath.append("\\Python\\Lib;");
  environPath.append(Base);
  environPath.append("\\Python\\Scripts;");
  environPath.append(Base);
  environPath.append("\\Python\\libs;");
  environPath.push_back('\0');
  
  std::string cmd = Base;
  cmd.append("\\Python\\python.exe");
  std::string params = "\"";
  params.append(cmd);
  params.append("\" \"");
  params.append(Base);
  params.append("\\Python\\_ML\\mlprocessor_server.py\"");
  </code></pre>
  
  <p>std::map env = { { "PYTHONPATH", environPython.data() },
                                      { "PATH", environPath.data() }};                                                     </p>
  
  <pre><code>// example for generating block of strings
  std::vector&lt;char&gt; envBlock;
  std::for_each(env.begin(), env.end(),
      [&amp;envBlock](const std::pair&lt;std::string, std::string&gt; &amp; p) {
      std::copy(p.first.begin(), p.first.end(), std::back_inserter(envBlock));
      envBlock.push_back('=');
      std::copy(p.second.begin(), p.second.end(),   std::back_inserter(envBlock));
      envBlock.push_back('\0');
  }
  );
  envBlock.push_back('\0');
  
  // feed this into ::CreateProcess()
  LPVOID lpEnvironment = (LPVOID)envBlock.data();
  
  bool result = CreateProcessA(cmd.c_str(), (LPSTR)params.c_str(), NULL, NULL, FALSE, CREATE_NO_WINDOW, lpEnvironment, NULL, &amp;info, &amp;pi);
  </code></pre>
  
  <hr>
  
  <p>The result is always true, python.exe is not shown up in task manager and gives Fatal Python error: failed to get random numbers to initialize Python.</p>
  
  <p>If the lpEnvironment is NULL, python.exe is shown up in task manager.</p>