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
Serial Connection Issue
This error AttributeError: module 'serial' has no attribute 'Serial' suggests that the package serial or a local file name serial.py has a conflict with pyserial. Rename your file to something else besides serial.py and/or uninstall the serial package (not needed for TCLab). Your pyserial package is the latest version.
pip uninstall serial
The error occurs when there is a local file named serial.py and we import from the pyserial module. Additional common TCLab help issues are posted to the TCLab setup and troubleshooting page.
Serial Port Permission
If the serial uninstall doesn't fix the problem of allowing a serial connection, one other thing to check is the USB port permission. On Linux, discover the USB port name with ls /dev/tty* Set the permission for that USB connection with the correct name.
sudo chmod a+rw /dev/ttyACM0
Python 3.10 Compatibility
You correctly found the issue with installing the latest version of TCLab for Python 3.10 compatibility. The module developer is still working on the next version of the TCLab package. Until that point, you can either edit the historian.py file (path is in the error message) with a text editor and change from collections import Iterable to from collections.abc import Iterable or install the new package from GitHub:
pip install --upgrade https://github.com/jckantor/TCLab/archive/master.zip
This will be resolved with the next release of TCLab on PyPI.org. The current version is 0.4.9 that does not include Python 3.10 compatibility because of the Iterable package change.
Related
I have tried run the pycel example in a clean virtualenv, after installing pycel package from source. The result is:
(py_cel) C:\Users\pena\Downloads\pycel\example>python --version
Python 3.9.7
(py_cel) C:\Users\pena\Downloads\pycel\example>pip list
Package Version
---------------- -------
decorator 5.1.1
et-xmlfile 1.1.0
networkx 2.4
numpy 1.23.4
openpyxl 3.2.0b1
pip 22.3.1
pycel 1.0b23
python-dateutil 2.8.2
ruamel.yaml 0.17.21
ruamel.yaml.clib 0.2.7
setuptools 65.5.1
six 1.16.0
wheel 0.38.4
(py_cel) C:\Users\pena\Downloads\pycel\example>python example.py
Loading C:\Users\pena\Downloads\pycel\example\example.xlsx...
C:\Users\pena\Documents\Heis\documentator\environ\py_cel\lib\site-packages\openpyxl-3.2.0b1-py3.9.egg\openpyxl\worksheet\_reader.py:332: UserWarning: Unknown extension is not supported and will be removed
warn(msg)
Traceback (most recent call last):
File "C:\Users\pena\Downloads\pycel\example\example.py", line 40, in <module>
excel = ExcelCompiler(filename=fname)
File "C:\Users\pena\Documents\Heis\documentator\environ\py_cel\lib\site-packages\pycel-1.0b23-py3.9.egg\pycel\excelcompiler.py", line 69, in __init__
self.excel.load()
File "C:\Users\pena\Documents\Heis\documentator\environ\py_cel\lib\site-packages\pycel-1.0b23-py3.9.egg\pycel\excelwrapper.py", line 241, in load
self.load_array_formulas()
File "C:\Users\pena\Documents\Heis\documentator\environ\py_cel\lib\site-packages\pycel-1.0b23-py3.9.egg\pycel\excelwrapper.py", line 246, in load_array_formulas
for address, props in ws.formula_attributes.items():
AttributeError: 'Worksheet' object has no attribute 'formula_attributes'
I would like to know how to run this example. Thanks.
I am trying to import a module that I know for a fact that was installed, but I am getting the ModuleNotFoundError: No module named '' error.
How can I solve this problem ?
HelendeMacBook-Pro:bin helendai$ pip3 list
Package Version
---------- ----------
certifi 2019.11.28
chardet 3.0.4
idna 2.9
pip 20.0.2
requests 2.23.0
setuptools 39.0.1
urllib3 1.25.8
wheel 0.31.0
HelendeMacBook-Pro:bin helendai$ python3 /Users/helendai/PycharmProjects/Demo1/test.py
Traceback (most recent call last):
File "/Users/helendai/PycharmProjects/Demo1/test.py", line 2, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
enter image description here
I have to run a python 3 script on a centos 7 host. I've installed python3.8 side by side with python2 so it doesn't break yum.
When I'm running the script I need to run I get this error:
Traceback (most recent call last):
File "A2PTestSuit.py", line 8, in <module>
import pandas as pd
File "/usr/local/lib/python3.8/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy: No module named '_ctypes'
If I list the modules I see that pandas and numpy are installed:
python3 -m pip list
Package Version
--------------- ----------
certifi 2019.11.28
chardet 3.0.4
DateTime 4.3
idna 2.8
numpy 1.18.1
pandas 0.25.3
pip 19.3.1
python-dateutil 2.8.1
pytz 2019.3
requests 2.22.0
setuptools 41.2.0
six 1.13.0
urllib3 1.25.7
zope.interface 4.7.1
How can I get past this error?
You can try updating all of your packages in the command line using pip, or just use try: import ... except ImportError: continue
I've got same issue. Problem was solved after I change default interpreter (which was Python 3.8) in PyCharm
I am trying to run daphne installed inside the virtualenv and the following are the errors:
Traceback (most recent call last):
File "/path-to-virtualenv/bin/daphne", line 7, in <module>
from daphne.cli import CommandLineInterface
File "/path-to-virtualenv/local/lib/python3.6/dist-packages/daphne/cli.py", line 7, in <module>
from .server import Server
File "/path-to-virtualenv/local/lib/python3.6/dist-packages/daphne/server.py", line 4, in <module>
from twisted.internet import asyncioreactor # isort:skip
ModuleNotFoundError: No module named 'twisted.internet'
Environment:
1. mac osx mojave
2. python 3.6.5
When I try to import the module twisted.internet after activating the virtualenv, it works without any problem.
When I try to run daphne without using the virtualenv (global install), it works without throwing any errors as shown.
Following are the packages installed (by pip install -U channels):
asgiref 2.3.2
async-timeout 3.0.0
attrs 18.2.0
autobahn 18.9.2
Automat 0.7.0
channels 2.1.3
constantly 15.1.0
daphne 2.2.2
Django 2.1.2
hyperlink 18.0.0
idna 2.7
incremental 17.5.0
pip 18.0
PyHamcrest 1.9.0
pytz 2018.5
setuptools 40.4.3
six 1.11.0
txaio 18.8.1
wheel 0.32.0
When I try to import ssl on any Python version I get
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/ssl.py", line 98, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: /lib/x86_64-linux-gnu/libssl.so.1.0.0: symbol X509_chain_up_ref, version
OPENSSL_1.0.2 not defined in file libcrypto.so.1.0.0 with link time reference
I have compiled Python 3.5 myself with libssl-dev version 1.0.2. According to aptitude I have libssl1.0.0.0 version 1.0.2 and openssl version 1.0.2 installed.
It seems to be a problem with the different version of libssl, openssl and libssl-dev but I have installed an reinstalled the newest version of all of them via the Package manager.
Im using Ubuntu 15.10 64-bit