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.
So, I'm trying to install and use the google-images-download repo both through: pip install google-images-download and pip install git+https://github.com/Joeclinton1/google-images-download.git
I've tried installing it as SU as well. In PyCharm when I view packages I do see it but when I try this code:
from google_images_download import google_images_download
#instantiate the class
response = google_images_download.googleimagesdownload()
arguments = {"keywords":"aeroplane, school bus, dog in front of house",
"limit":10,"print_urls":False}
paths = response.download(arguments)
#print complete paths to the downloaded images
print(paths)
it gives this error continuously:
Traceback (most recent call last):
File "/Users/*x*/Desktop/SchoolPython/PythonUVA/Webscrape.py", line 1, in <module>
from google_images_download import google_images_download
ModuleNotFoundError: No module named 'google_images_download'
I think it might not be looking in the right filepath or library but any other repo I tried previously did work.
Any help is greatly appreciated.
*edit for versions
(3.9UVA) MacBook-Pro-van-Flavia:Webscrape.py flavia$ which pip
/Users/flavia/PycharmProjects/3.9UVA/bin/pip
(3.9UVA) MacBook-Pro-van-Flavia:Webscrape.py flavia$ which python
/Users/flavia/PycharmProjects/3.9UVA/bin/python
(3.9UVA) MacBook-Pro-van-Flavia:Webscrape.py flavia$ pip list
Package Version
---------------------- -----------
async-generator 1.10
attrs 21.4.0
certifi 2022.5.18.1
cffi 1.15.0
charset-normalizer 2.0.12
cryptography 37.0.2
google-images-download 2.8.0
h11 0.13.0
idna 3.3
outcome 1.1.0
Pillow 9.1.1
pip 21.3.1
pycparser 2.21
pyOpenSSL 22.0.0
PySocks 1.7.1
requests 2.27.1
selenium 4.2.0
setuptools 60.2.0
sniffio 1.2.0
sortedcontainers 2.4.0
trio 0.20.0
trio-websocket 0.9.2
urllib3 1.26.9
wheel 0.37.1
wsproto 1.1.0
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 having problems getting a program to import the mysql.connector
Note: Running on a Windows 10 machine.
I have done the following
1) Installed anaconda (install properly)
I checked that the anaconda paths are in my pathname variable
Here is the PATH var:
C:\Users\john.fox\AppData\Local\Continuum\anaconda3;C:\Users\john.fox\AppData\Local\Continuum\anaconda3\Library\mingw-w64\bin;C:\Users\john.fox\AppData\Local\Continuum\anaconda3\Library\usr\bin;C:\Users\john.fox\AppData\Local\Continuum\anaconda3\Library\bin;C:\Users\john.fox\AppData\Local\Continuum\anaconda3\Scripts;C:\Users\john.fox\AppData\Local\Continuum\anaconda3\envs\Python34;
2) Change the python version to python3.4 (was python3.6)
This was needed to get mysql-connector to work properly
The Python34 path is in the pathname variable
3) Installed the mysql-connector using anaconda (installed correctly)
4) Did a "conda search mysql-connector"
It came back with all the mysql.connectors (the one for py34_0 is present)
C:\Users\john.fox>conda search mysql.connector
Fetching package metadata .............
mysql-connector-python 2.0.3 py26_0 defaults
2.0.3 py27_0 defaults
2.0.3 py33_0 defaults
2.0.3 py34_0 defaults
2.0.3 py35_0 defaults
2.0.4 py27_0 defaults
2.0.4 py34_0 defaults
2.0.4 py35_0 defaults
2.0.4 py36_0 defaults
5) Attempted to run a script with import mysql.connector
Received:
Traceback (most recent call last):
File "jira_export5_Beta.py", line 3, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
6) Went to Python 3.6.2 for default
7) Attempted to run again, same results.
If anyone has words of wisdom (for this problem) I would appreciate hearing them.
Thanks JWF
I have installed pyOpenSSL and all the required packages but i can't import OpenSSL in the shell . I get this error :
>>> import OpenSSL
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named OpenSSL
list of required packages that are allready installed:
cryptography (0.9.3)
distribute (0.7.3)
idna (2.0)
pip (7.1.0)
pyasn1 (0.1.8)
pyasn1-modules (0.0.5)
pyopenssl (0.15.1)
requests (2.7.0)
service-identity (14.0.0)
setuptools (18.1)
six (1.9.0)
Twisted (15.2.1)
urllib3 (1.11)
w3lib (1.12.0)
zope.interface (4.1.2)
If you are running a 64-bit version of Windows then I recommend you install a Win64 version of OpenSSL, available from https://slproweb.com/products/Win32OpenSSL.html (scroll down until you find the 64 bit installers) and the 64-bit version of pyOpenSSL, available from http://www.egenix.com/products/python/pyOpenSSL/
Check that you don't have 32-bit versions of the various products, python-packages, etc. I had some site-packages on the PYTHONPATH which confused python. I removed the environment variable PYTHONPATH and similarly PYTHONUSERBASE (both were recommended by some software I was trying where they wanted to use 32-bit versions of mitmproxy and working backwards everything else...) I want to retain my 64-bit version of Python (2.7.6) hence my struggles as I ran into the same error you reported here.