diff --git a/rclpy/package.xml b/rclpy/package.xml index 19e731d18..7b98159e7 100644 --- a/rclpy/package.xml +++ b/rclpy/package.xml @@ -27,6 +27,7 @@ builtin_interfaces rcl_interfaces rosgraph_msgs + rpyutils ament_cmake_gtest ament_cmake_pytest diff --git a/rclpy/rclpy/impl/__init__.py b/rclpy/rclpy/impl/__init__.py index 92926f7e6..8fa489133 100644 --- a/rclpy/rclpy/impl/__init__.py +++ b/rclpy/rclpy/impl/__init__.py @@ -15,10 +15,16 @@ import importlib import os +from rpyutils import add_dll_directories_from_env + def _import(name): try: - return importlib.import_module(name, package='rclpy') + # Since Python 3.8, on Windows we should ensure DLL directories are explicitly added + # to the search path. + # See https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew + with add_dll_directories_from_env('PATH'): + return importlib.import_module(name, package='rclpy') except ImportError as e: if e.path is not None and os.path.isfile(e.path): e.msg += \ diff --git a/rclpy/test/__init__.py b/rclpy/test/__init__.py index 8f1a3098a..d1a5be1e2 100644 --- a/rclpy/test/__init__.py +++ b/rclpy/test/__init__.py @@ -15,6 +15,8 @@ import importlib import sys +from rpyutils import add_dll_directories_from_env + assert 'rclpy' not in sys.modules, 'rclpy should not have been imported before running tests' # this will make the extensions load from the build folder @@ -23,7 +25,11 @@ def _custom_import(name): - return importlib.import_module(name, package='test_rclpy') + # Since Python 3.8, on Windows we should ensure DLL directories are explicitly added + # to the search path. + # See https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew + with add_dll_directories_from_env('PATH'): + return importlib.import_module(name, package='test_rclpy') rclpy.impl._import = _custom_import