diff --git a/colcon_core/task/python/build.py b/colcon_core/task/python/build.py index a72c1a54e..5320a939c 100644 --- a/colcon_core/task/python/build.py +++ b/colcon_core/task/python/build.py @@ -70,6 +70,7 @@ async def build(self, *, additional_hooks=None): # noqa: D102 Path(__file__).parent / 'template' / 'sitecustomize.py.em', prefix_override / 'sitecustomize.py', { + 'current_prefix': sys.prefix, 'site_prefix': args.install_base, }) diff --git a/colcon_core/task/python/template/sitecustomize.py.em b/colcon_core/task/python/template/sitecustomize.py.em index 5ed6f35ef..b6bbe2f03 100644 --- a/colcon_core/task/python/template/sitecustomize.py.em +++ b/colcon_core/task/python/template/sitecustomize.py.em @@ -1,3 +1,4 @@ import sys -sys.real_prefix = sys.prefix -sys.prefix = sys.exec_prefix = @repr(site_prefix) +if sys.prefix == @repr(current_prefix): + sys.real_prefix = sys.prefix + sys.prefix = sys.exec_prefix = @repr(site_prefix)