From c093bd2f816d8df26f45eb42d174567cc4d9fb69 Mon Sep 17 00:00:00 2001 From: AURUMVORXX Date: Wed, 26 Mar 2025 16:28:49 +0300 Subject: [PATCH] feat: Virtual env site-packages auto add to sys.path --- source/main.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 8c91fac..05ffaca 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -25,14 +25,13 @@ extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api) import importlib import importlib.util site.addsitedir('.') - - spec = importlib.util.find_spec("g2o") - if spec is not None: - if spec.submodule_search_locations: - sys.path.append(spec.submodule_search_locations[0]) - - entry_point = 'pyg2o_entry' + import os + if 'VIRTUAL_ENV' in os.environ: + packages_path = os.path.join(os.environ['VIRTUAL_ENV'], 'Lib', 'site-packages') + sys.path.append(packages_path) + + entry_point = 'pyg2o_entry' try: with open('pyg2o.json', 'r') as f: json = json.loads(f.read()) @@ -47,6 +46,12 @@ extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api) sys.path.append(spec.submodule_search_locations[0]) except Exception as e: print(e) + + spec = importlib.util.find_spec('g2o') + if spec is not None: + if spec.submodule_search_locations: + sys.path.append(spec.submodule_search_locations[0]) + )", py::globals(), locals); registerSquirrelConstants();