diff --git a/bluesky/resourcepath.py b/bluesky/resourcepath.py index cc59a24a95..4ff8b118e3 100644 --- a/bluesky/resourcepath.py +++ b/bluesky/resourcepath.py @@ -2,8 +2,13 @@ import shutil import itertools from pathlib import Path -from importlib.resources import files -from importlib.readers import MultiplexedPath +try: + from importlib.resources import files + from importlib.readers import MultiplexedPath +except ImportError: + # Python < 3.9 only provides deprecated resources API + from importlib_resources import files + from importlib_resources.readers import MultiplexedPath class ResourcePath(MultiplexedPath): diff --git a/setup.py b/setup.py index e29fd5ae8e..275cb67376 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ # Always prefer setuptools over distutils import os +import sys from pathlib import Path from setuptools import setup, find_packages, Extension import configparser @@ -16,6 +17,9 @@ with open(os.path.join(here, 'requirements.txt'), encoding='utf-8') as f: install_requires = f.readlines() +# If Python version < 3.9, add importlib_resources requirement +if sys.version_info.major == 3 and sys.version_info.minor < 9: + install_requires.append('importlib_resources') # get extra requirements from setup.cfg parser = configparser.ConfigParser()