title: Embedding python with pybind11. Virtual environment doesn't work
body: <p>I am trying to make a simple c++ application which translates phrases using <code>googletrans</code> python library. So I've chosen <strong>pybind11</strong> for this purpose to <strong>embed python</strong>. Also I use cmake for code configuration.</p>
  
  <p>Everything works just fine when I'm using the global python installation, but <strong>I don't understand how to use virtual environment with pybind</strong> and the whole process of setting the correct python interpreter, paths etc. in cmake much.</p>
  
  <p>I've found this stackoverflow thread: <a href="https://stackoverflow.com/questions/53480120/embedding-pybind11-with-virtual-environment">Embedding pybind11 with virtual environment</a></p>
  
  <p>I set all the variables as @ipa did.
  Just look at the <code>CMakeLists.txt</code> and <code>main.cpp</code>:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.15)
  project("cpp_google_trans")
  
  set(
      PYTHON_EXECUTABLE "${CMAKE_HOME_DIRECTORY}/venv/Scripts/python.exe"
      CACHE FILEPATH "python virtual environment executable")
  message(STATUS "PYTHON_EXECUTABLE is now: ${PYTHON_EXECUTABLE}")    #DEBUG
  
  set(ENV{PYTHONPATH} "${CMAKE_HOME_DIRECTORY}/venv/Lib/site-packages")
  message(STATUS "ENV{PYTHONPATH} is now: $ENV{PYTHONPATH}")  #DEBUG
  
  set(
      ENV{PATH}
      "${CMAKE_HOME_DIRECTORY}/venv/Scripts/;${CMAKE_HOME_DIRECTORY}/venv/Lib"
  )
  message(STATUS "PATH is now: $ENV{PATH}")   #DEBUG
  
  add_subdirectory(pybind11)
  
  add_executable(app main.cpp)
  target_link_libraries(app PRIVATE pybind11::embed)
  </code></pre>
  
  <p><code>main.cpp</code>:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;pybind11/embed.h&gt;
  namespace py = pybind11;
  
  int main() {
      py::scoped_interpreter guard{};
  
      auto sys = py::module::import("sys");
      py::print("Hello, World from Python!");
      py::print(sys.attr("executable"));
      py::print(sys.attr("version"));
  
      system("set PATH");
  
      std::cin.get();
  
      // system("powershell");
      // I was looking at the environment variables in the powershell, but there wasn't any variables I set in CMakeLists.txt
  
      // Here I get abort() when trying to import googletrans package.
      // The package is installed in the venv virtual environment.
      // When the package is installed globally there isn't any problem.
      py::object Translator = py::module::import("googletrans").attr("Translator");
      py::object translator = Translator();
  
      std::cout &lt;&lt; "C++ program here!\nTell a phrase you want to translate to english: ";
      std::string phrase;
      std::getline(std::cin, phrase);
  
      std::cout &lt;&lt; "\n\nThe phrase in english means: ";
      std::cout &lt;&lt; translator.attr("translate")(py::cast(&amp;phrase)).attr("text").cast&lt;std::string&gt;();
  }
  </code></pre>
  
  <p>When looking at the cmake configuration output everything seems working well (instead of PythonLibs variable I don't know how to change):</p>
  
  <pre><code>-- Building for: Visual Studio 16 2019
  -- The C compiler identification is MSVC 19.22.27812.2
  -- The CXX compiler identification is MSVC 19.22.27812.2
  -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.22.27812/bin/Hostx64/x64/cl.exe
  -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.22.27812/bin/Hostx64/x64/cl.exe -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.22.27812/bin/Hostx64/x64/cl.exe
  -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.22.27812/bin/Hostx64/x64/cl.exe -- works
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- PYTHON_EXECUTABLE is now: D:/dev/Pybind/cpp_google_trans2/venv/Scripts/python.exe
  -- ENV{PYTHONPATH} is now: D:/dev/Pybind/cpp_google_trans2/venv/Lib/site-packages
  -- PATH is now: D:/dev/Pybind/cpp_google_trans2/venv/Scripts/;D:/dev/Pybind/cpp_google_trans2/venv/Lib    
  -- Found PythonInterp: D:/dev/Pybind/cpp_google_trans2/venv/Scripts/python.exe (found version "3.7.3")    
  -- Found PythonLibs: D:/Programs/VisualStudio/Shared/Python37_64/libs/Python37.lib
  -- pybind11 v2.3.dev1
  -- Configuring done
  -- Generating done
  -- Build files have been written to: D:/dev/Pybind/cpp_google_trans2/build
  </code></pre>
  
  <p>I also tried to set PYTHON_EXECUTABLE and PATH environment variables globally through <code>control panel&gt;system and security&gt;system&gt;advanced system settings&gt;advanced&gt;environment variables</code>, but even this didn't help.</p>
  
  <p>I am still pretty new to cmake, python and pybind11 and I am aware of that I don't know a lot of things. And maybe you've noticed this while reading this thread. ;P</p>