summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/_dtype_ctypes.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/numpy/core/_dtype_ctypes.py b/numpy/core/_dtype_ctypes.py
index 708241289..6d7cbb244 100644
--- a/numpy/core/_dtype_ctypes.py
+++ b/numpy/core/_dtype_ctypes.py
@@ -22,9 +22,10 @@ Unfortunately, this fails because:
* PEP3118 cannot represent unions, but both numpy and ctypes can
* ctypes cannot handle big-endian structs with PEP3118 (bpo-32780)
"""
-import _ctypes
-import ctypes
+# We delay-import ctypes for distributions that do not include it.
+# While this module is not used unless the user passes in ctypes
+# members, it is eagerly imported from numpy/core/__init__.py.
import numpy as np
@@ -39,6 +40,7 @@ def _from_ctypes_structure(t):
"ctypes bitfields have no dtype equivalent")
if hasattr(t, "_pack_"):
+ import ctypes
formats = []
offsets = []
names = []
@@ -79,6 +81,7 @@ def _from_ctypes_scalar(t):
def _from_ctypes_union(t):
+ import ctypes
formats = []
offsets = []
names = []
@@ -98,6 +101,7 @@ def dtype_from_ctypes_type(t):
"""
Construct a dtype object from a ctypes type
"""
+ import _ctypes
if issubclass(t, _ctypes.Array):
return _from_ctypes_array(t)
elif issubclass(t, _ctypes._Pointer):