OS:
macOS 11.7.1 (Big Sur)
A few months ago I purchased a TCLab kit and at the time did some very rudimentary tests where the device worked as expected.
Recently I decided that I wanted to work on some of the APMonitor lessons and connected the TCLab to my computer expecting that it would work as it had done in the past.
Sadly, that is not the case. I would like help in correcting the issues identified and getting the TCLab to work again.
Originally, I had been using python 3.9
. Since then python 3.10
came out and I installed it.
Using the following script from APMonitor as my test,
$ cat show_T1.py
import tclab
with tclab.TCLab() as lab:
print(lab.T1)
I got the errors documented below:
$ python --version
Python 3.10.8
$ python show_T1.py
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/show_T1.py", line 1, in <module>
import tclab
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv3.10/lib/python3.10/site-packages/tclab/__init__.py", line 2, in <module>
from .historian import Historian, Plotter
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv3.10/lib/python3.10/site-packages/tclab/historian.py", line 6, in <module>
from collections import Iterable
ImportError: cannot import name 'Iterable' from 'collections' (/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/__init__.py)
I was able to find the cause of this problem here: Stack Overflow It is an issue where Iterable
was moved to collections.abc
from collections
.
When I change the script to:
$ cat show_T1.py
import collections.abc
collections.Iterable = collections.abc.Iterable
collections.Mapping = collections.abc.Mapping
collections.MutableSet = collections.abc.MutableSet
collections.MutableMapping = collections.abc.MutableMapping
import tclab
with tclab.TCLab() as lab:
print(lab.T1)
the import error goes away. However, I now get new errors:
$ python show_T1.py
TCLab version 0.4.9
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv3.10/lib/python3.10/site-packages/tclab/tclab.py", line 64, in __init__
self.connect(baud=115200)
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv3.10/lib/python3.10/site-packages/tclab/tclab.py", line 114, in connect
self.sp = serial.Serial(port=self.port, baudrate=baud, timeout=2)
AttributeError: module 'serial' has no attribute 'Serial'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv3.10/lib/python3.10/site-packages/tclab/tclab.py", line 70, in __init__
self.sp.close()
AttributeError: 'TCLab' object has no attribute 'sp'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/show_T1.py", line 7, in <module>
with tclab.TCLab() as lab:
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv3.10/lib/python3.10/site-packages/tclab/tclab.py", line 77, in __init__
raise RuntimeError('Failed to Connect.')
RuntimeError: Failed to Connect.
Sadly, I get almost the same error as above if I revert back to python 3.9
: (python 3.9 does not have the Iterable
problem, so I reverted back to the original script):
$ python --version
Python 3.9.15
$ python show_T1.py
TCLab version 0.4.9
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv/lib/python3.9/site-packages/tclab/tclab.py", line 64, in __init__
self.connect(baud=115200)
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv/lib/python3.9/site-packages/tclab/tclab.py", line 114, in connect
self.sp = serial.Serial(port=self.port, baudrate=baud, timeout=2)
AttributeError: module 'serial' has no attribute 'Serial'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv/lib/python3.9/site-packages/tclab/tclab.py", line 70, in __init__
self.sp.close()
AttributeError: 'TCLab' object has no attribute 'sp'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/show_T1.py", line 2, in <module>
with tclab.TCLab() as lab:
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv/lib/python3.9/site-packages/tclab/tclab.py", line 77, in __init__
raise RuntimeError('Failed to Connect.')
RuntimeError: Failed to Connect.
I know that at least I have connectivity to the device, because when I unplug the USB cable I get an error message that says, correctly, that no arduino is connected:
$ python show_T1.py
TCLab version 0.4.9
--- Serial Ports ---
/dev/cu.Bluetooth-Incoming-Port n/a n/a
Traceback (most recent call last):
File "/Users/USER/TClab/arduino/0_Test_Device/Python/show_T1.py", line 2, in <module>
with tclab.TCLab() as lab:
File "/Users/USER/TClab/arduino/0_Test_Device/Python/venv/lib/python3.9/site-packages/tclab/tclab.py", line 61, in __init__
raise RuntimeError('No Arduino device found.')
RuntimeError: No Arduino device found.
Below are the python modules I have installed under python 3.10 and 3.9:
python 3.10:
$ pip list
Package Version
------------------ ---------
blessed 1.19.1
bpython 0.23
certifi 2022.9.24
charset-normalizer 2.1.1
contourpy 1.0.6
curtsies 0.4.1
cwcwidth 0.1.8
cycler 0.11.0
fonttools 4.38.0
future 0.18.2
greenlet 2.0.1
idna 3.4
iso8601 1.1.0
kiwisolver 1.4.4
matplotlib 3.6.2
numpy 1.23.5
packaging 21.3
Pillow 9.3.0
pip 22.3.1
Pygments 2.13.0
pyparsing 3.0.9
pyserial 3.5
python-dateutil 2.8.2
pyxdg 0.28
PyYAML 6.0
requests 2.28.1
scipy 1.9.3
serial 0.0.97
setuptools 65.4.1
six 1.16.0
tclab 0.4.9
urllib3 1.26.13
wcwidth 0.2.5
python 3.9:
$ pip list
Package Version
------------------ ---------
blessed 1.19.1
bpython 0.23
certifi 2022.9.24
charset-normalizer 2.1.1
contourpy 1.0.6
curtsies 0.4.1
cwcwidth 0.1.8
cycler 0.11.0
docopt 0.6.2
fonttools 4.38.0
future 0.18.2
greenlet 2.0.1
idna 3.4
iso8601 1.1.0
kiwisolver 1.4.4
matplotlib 3.6.2
numpy 1.23.5
packaging 21.3
Pillow 9.3.0
pip 22.3.1
pipreqs 0.4.11
Pygments 2.13.0
pyparsing 3.0.9
pyserial 3.5
python-dateutil 2.8.2
pyxdg 0.28
PyYAML 6.0
requests 2.28.1
scipy 1.9.3
serial 0.0.97
setuptools 65.4.1
six 1.16.0
tclab 0.4.9
urllib3 1.26.13
wcwidth 0.2.5
yarg 0.1.9
NOTE: I have send this issue to support@apmonitor.com