diff --git a/src/EnergyPlus/PluginManager.cc b/src/EnergyPlus/PluginManager.cc index 8a47c02da96..7438f1e906a 100644 --- a/src/EnergyPlus/PluginManager.cc +++ b/src/EnergyPlus/PluginManager.cc @@ -406,6 +406,11 @@ namespace EnergyPlus::PluginManagement { Py_SetPath(a); Py_SetPythonHome(a); + // must be called before Py_Initialize + // tells the interpreter the value of argv[0] to the main() function + // used by some functions to find run-time libraries relative to the interpreter executable + Py_SetProgramName((wchar_t*)programName); + // now that we have set the path, we can initialize python // from https://docs.python.org/3/c-api/init.html // If arg 0, it skips init registration of signal handlers, which might be useful when Python is embedded. diff --git a/src/EnergyPlus/PluginManager.hh b/src/EnergyPlus/PluginManager.hh index 1ebcc0e8366..fb1bad11bc5 100644 --- a/src/EnergyPlus/PluginManager.hh +++ b/src/EnergyPlus/PluginManager.hh @@ -80,6 +80,8 @@ struct EnergyPlusData; namespace PluginManagement { + constexpr const char * programName = "python"; + void registerNewCallback(EnergyPlusData &state, EMSManager::EMSCallFrom iCalledFrom, const std::function& f); void runAnyRegisteredCallbacks(EnergyPlusData &state, EMSManager::EMSCallFrom iCalledFrom, bool &anyRan); void onBeginEnvironment(EnergyPlusData &state); diff --git a/src/EnergyPlus/api/plugin.py b/src/EnergyPlus/api/plugin.py index 589d7f7f62a..9ef552b1715 100644 --- a/src/EnergyPlus/api/plugin.py +++ b/src/EnergyPlus/api/plugin.py @@ -53,6 +53,10 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. +import sys +if not hasattr(sys, 'argv'): + sys.argv = [''] + from typing import List from pyenergyplus.api import EnergyPlusAPI