diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 683382d6bcb464540e62e0832c9a950a41b01d76..bda4800bf95ba8671d7fa7bc60e92f0192a4cd14 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -255,23 +255,19 @@ def compiler_output(text): # {{{ find pyopencl shipped source code def _find_pyopencl_include_path(): - from pkg_resources import Requirement, resource_filename, DistributionNotFound + from os.path import join, abspath, dirname, exists try: + # Try to find the include path in the same directory as this file + include_path = join(abspath(dirname(__file__)), "cl") + if not exists(include_path): + raise IOError() + except Exception: # Try to find the resource with pkg_resources (the recommended - # setuptools approach) + # setuptools approach). This is very slow. + from pkg_resources import (Requirement, resource_filename, + DistributionNotFound) include_path = resource_filename( Requirement.parse("pyopencl"), "pyopencl/cl") - except DistributionNotFound: - # If pkg_resources can't find it (e.g. if the module is part of a - # frozen application), try to find the include path in the same - # directory as this file - from os.path import join, abspath, dirname, exists - - include_path = join(abspath(dirname(__file__)), "cl") - # If that doesn't exist, just re-raise the exception caught from - # resource_filename. - if not exists(include_path): - raise # Quote the path if it contains a space and is not quoted already. # See https://github.com/inducer/pyopencl/issues/250 for discussion.