c++ – Embedded python interpreter won’t use virtual conda environment

I am trying to build a C++ program that embeds the python interpreter using pybind11. I am using Visual Studio 2019 on Windows with a C++ project (not CMake).

I want to use the packages that are inside a virtual conda environment (Anaconda3/envs/pytorchenv) rather than the root environment. The problem that I can’t seem to get past is that the program uses the python installation in the Anaconda root environment no matter what I do.

Even if I “conda activate” the virtual environment in an Anaconda prompt before launching the program – it still uses the root environment. (I’m not sure if “conda activate” is supposed to modify PATH, but when I check my system environment variables, it doesn’t change them).

I’m guessing there is something I can set in my Visual Studio project settings to indicate that I want pybind11 to use the virtual environment instead of the conda base path. Any help would be greatly appreciated. Thanks!

Read more here: Source link