From 943f34fdfa7eb3cb891fd0f0798f99050a48d8d8 Mon Sep 17 00:00:00 2001 From: karolamik13 Date: Tue, 17 Dec 2024 09:25:49 +0100 Subject: [PATCH] checkAndImport for Py3 and Py2.7 --- prody/proteins/channels.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/prody/proteins/channels.py b/prody/proteins/channels.py index b0a49d250..1c311b14e 100644 --- a/prody/proteins/channels.py +++ b/prody/proteins/channels.py @@ -47,10 +47,18 @@ def checkAndImport(package_name): if not isinstance(package_name, str): raise TypeError('package_name should be a string') - import importlib.util - if importlib.util.find_spec(package_name) is None: - LOGGER.warn("Package " + str(package_name) + " is not installed. Please install it to use this function.") - return False + if PY3K: + import importlib.util + if importlib.util.find_spec(package_name) is None: + LOGGER.warn("Package " + str(package_name) + " is not installed. Please install it to use this function.") + return False + else: + try: + __import__(package_name) + except ImportError: + LOGGER.warn("Package " + str(package_name) + " is not installed. Please install it to use this function.") + return False + return True def getVmdModel(vmd_path, atoms):