title: Fatal Python error: Py_Initialize: unable to load the file system codec & ModuleNotFoundError
body: <h2>Intention</h2>
  
  <p>I want to access a python function from C++ and am using C++17 and Python 3.7.3.</p>
  
  <h2>My Visual Studio Project settings</h2>
  
  <ul>
  <li>C/C++ > General > Additional include directories > "D:\Programme\vcpkg\installed\x64-windows\include\python3.6"</li>
  <li>Linker > General > Additional library directories > "D:\Programme\vcpkg\installed\x64-windows\lib"</li>
  <li>Linker > Input > Additional Dependencies > python36.lib;...</li>
  </ul>
  
  <h2>Main.cpp</h2>
  
  <pre><code>#include &lt;Python.h&gt;
  #include &lt;iostream&gt;
  #include "tchar.h"
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      printf("Calling Python to find the sum of 2 and 2.\n");
  
      // Initialize the Python interpreter.
      Py_Initialize();
  
      // Create some Python objects that will later be assigned values.
      PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue;
  
      // Convert the file name to a Python string.
      pName = PyUnicode_FromString("Sample");
  
      // Import the file as a Python module.
      pModule = PyImport_Import(pName);
  
      // Create a dictionary for the contents of the module.
      pDict = PyModule_GetDict(pModule);
  
      // Get the add method from the dictionary.
      pFunc = PyDict_GetItemString(pDict, "add");
  
      // Create a Python tuple to hold the arguments to the method.
      pArgs = PyTuple_New(2);
  
      // Convert 2 to a Python integer.
      pValue = PyLong_FromLong(2);
  
      // Set the Python int as the first and second arguments to the method.
      PyTuple_SetItem(pArgs, 0, pValue);
      PyTuple_SetItem(pArgs, 1, pValue);
  
      // Call the function with the arguments.
      PyObject* pResult = PyObject_CallObject(pFunc, pArgs);
  
      // Print a message if calling the method failed.
      if (pResult == NULL)
          printf("Calling the add method failed.\n");
  
      // Convert the result to a long from a Python object.
      long result = PyLong_AsLong(pResult);
  
      // Destroy the Python interpreter.
      Py_Finalize();
  
      // Print the result.
      printf("The result is %d.\n", result); std::cin.ignore(); return 0;
  }
  </code></pre>
  
  <h2>Sample.py</h2>
  
  <pre><code># Returns the sum of two numbers.
  def add(a, b):
      return a + b
  </code></pre>
  
  <h2>My directories</h2>
  
  <p><a href="https://i.stack.imgur.com/Y1M4f.png" rel="nofollow noreferrer">directory of files</a></p>
  
  <p><a href="https://i.stack.imgur.com/oC3eQ.png" rel="nofollow noreferrer">release version</a></p>
  
  <p><a href="https://i.stack.imgur.com/v73OX.png" rel="nofollow noreferrer">solution directory</a></p>
  
  <h2>The error</h2>
  
  <pre><code>Calling Python to find the sum of 2 and 2.
  Fatal Python error: Py_Initialize: unable to load the file system codec
  ModuleNotFoundError: No module named 'encodings'
  
  Current thread 0x00003ca0 (most recent call first):
  </code></pre>