Skip to content

Commit f80c824

Browse files
committed
microscope/_utils.py: check we imported pySerial's serial package (#232)
1 parent f190c7b commit f80c824

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

microscope/_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@
2626
import microscope.abc
2727

2828

29+
# Both pySerial and serial distribution packages install an import
30+
# package named serial. If both are installed we may have imported
31+
# the wrong one. Check it to provide a better error message. See
32+
# issue #232.
33+
if not hasattr(serial, "Serial"):
34+
if hasattr(serial, "marshall"):
35+
raise microscope.MicroscopeError(
36+
"incorrect imported package serial. It appears that the serial"
37+
" package from the distribution serial, instead of pyserial, was"
38+
" imported. Consider uninstalling serial and installing pySerial."
39+
)
40+
else:
41+
raise microscope.MicroscopeError(
42+
"imported package serial does not have Serial class"
43+
)
44+
45+
2946
class OnlyTriggersOnceOnSoftwareMixin(microscope.abc.TriggerTargetMixin):
3047
"""Utility mixin for devices that only trigger "once" with software.
3148

0 commit comments

Comments
 (0)