Unable to run pycel example - python

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.

Related

TCLab issues with python 3.10 (and python 3.9)

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.

Jupyter Labs ModuleNotFoundError: No module named 'traitlets.utils.descriptions'

I would like to install jupyter labs on my linux system. I have python3.9 installed so I run pip install jupyterlab as per official documentation.
After the download is finnished, I get the following error:
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
notebook 6.3.0 requires nbconvert==6.0.7, but you have nbconvert 6.5.0 which is incompatible.
notebook 6.3.0 requires nbformat==5.1.3, but you have nbformat 5.4.0 which is incompatible.
notebook 6.3.0 requires traitlets==4.3.3, but you have traitlets 5.3.0 which is incompatible.
Weird, but I have tried intalling all of these manually afterwards using pip install nbformat==5.1.3 and so on...
After the installation, I run jupyter lab, and the following error appers:
Traceback (most recent call last):
File "/root/venv/bin/jupyter-lab", line 5, in <module>
from jupyterlab.labapp import main
File "/root/venv/lib/python3.9/site-packages/jupyterlab/labapp.py", line 13, in <module>
from jupyter_server.serverapp import flags
File "/root/venv/lib/python3.9/site-packages/jupyter_server/serverapp.py", line 105, in <module>
from jupyter_server.gateway.managers import (
File "/root/venv/lib/python3.9/site-packages/jupyter_server/gateway/managers.py", line 25, in <module>
from ..services.sessions.sessionmanager import SessionManager
File "/root/venv/lib/python3.9/site-packages/jupyter_server/services/sessions/sessionmanager.py", line 20, in <module>
from jupyter_server.traittypes import InstanceFromClasses
File "/root/venv/lib/python3.9/site-packages/jupyter_server/traittypes.py", line 5, in <module>
from traitlets.utils.descriptions import describe
ModuleNotFoundError: No module named 'traitlets.utils.descriptions'
I have tried installing traitlets, but indeed when I run:
import traitlets
traitlets.utils.descriptions
I get:
AttributeError: module 'traitlets.utils' has no attribute 'descriptions'
Maybe this is the wrong version of the module? Which one should I install then?

robot framework library JSONlibrary import error

I am having issues with importing JSONlibrary and I am not sure where it fails.
I'm getting the following errors:
[ ERROR ] Error in file 'C:\Users\path\to\file.robot' on line 12: Importing test library 'JSONLibrary' failed: SyntaxError: no viable alternative at input 'from' (__init__.py, line 1367)
Traceback (most recent call last):
File "C:\Users\path\to\Python\Python37-32\Lib\site-packages\JSONLibrary\__init__.py", line 2, in <module>
from .JSONLibraryKeywords import JSONLibraryKeywords
File "C:\Users\path\to\Python\Python37-32\Lib\site-packages\JSONLibrary\JSONLibraryKeywords.py", line 7, in <module>
from jsonpath_rw_ext import parse
File "C:\Users\path\to\Python\Python37-32\Lib\site-packages\jsonpath_rw_ext\__init__.py", line 17, in <module>
__version__ = pbr.version.VersionInfo(
File "C:\Users\path\to\Python\Python37-32\Lib\site-packages\pbr\version.py", line 467, in version_string
return self.semantic_version().brief_string()
File "C:\Users\path\to\Python\Python37-32\Lib\site-packages\pbr\version.py", line 462, in semantic_version
self._semantic = self._get_version_from_pkg_resources()
File "C:\Users\path\to\Python\Python37-32\Lib\site-packages\pbr\version.py", line 439, in _get_version_from_pkg_resources
import pkg_resources
I tried to pip reinstall robotframework-jsonlibrary and pkg_resources, but it still does not work. It seems that some of the code may be in python 2?
Currently using Robot Framework 3.2.2 (Python 3.7.9 on win32) and pip list:
appdirs 1.4.4
certifi 2020.6.20
chardet 3.0.4
configparser 5.0.0
coverage 5.3
decorator 4.4.2
distlib 0.3.1
filelock 3.0.12
idna 2.10
importlib-metadata 1.7.0
jsonpath-rw 1.4.0
jsonpath-rw-ext 1.2.2
pbr 5.5.0
pip 20.1.1
pluggy 0.13.1
ply 3.11
py 1.9.0
requests 2.24.0
robotframework 3.2.2
robotframework-jsonlibrary 0.3.1
robotframework-requests 0.7.1
setuptools 50.3.0
six 1.15.0
tox 3.0.0
urllib3 1.25.10
virtualenv 20.0.31
zipp 3.1.0

Python - numpy: No module named '_ctypes'

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

How to fix Python import error for Crypto.Signature.DSS

I am trying to run the pycryptodome example for DSA. Here is the example code:
from Crypto.PublicKey import DSA
from Crypto.Signature import DSS
from Crypto.Hash import SHA256
# Create a new DSA key
key = DSA.generate(2048)
f = open("public_key.pem", "w")
f.write(key.publickey().export_key())
f.close()
# Sign a message
message = b"Hello"
hash_obj = SHA256.new(message)
signer = DSS.new(key, 'fips-186-3')
signature = signer.sign(hash_obj)
But I am facing ImportError for DSS. Here is the error output:
Traceback (most recent call last):
File "/usr/lib/python3.6/code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "/snap/pycharm-professional/154/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/snap/pycharm-professional/154/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/username/Projects/DSA_Example.py", line 2, in <module>
from Crypto.Signature import DSS
ImportError: cannot import name 'DSS'
My development environment includes:
Ubuntu 18.04.3 LTS
Python 3.6.8
PyCharm IDE 2019.2
Using venv Python virtual environment
pip list command shows:
(venv) username#myubuntu:~/Projects/MyProject/$ pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
asn1crypto (0.24.0)
cryptography (2.1.4)
decorator (4.1.2)
enum34 (1.1.6)
idna (2.6)
ipaddress (1.0.17)
keyring (10.6.0)
keyrings.alt (3.0)
networkx (1.11)
numpy (1.13.3)
pip (9.0.1)
pycrypto (2.6.1)
pycryptodome (3.9.0)
pygobject (3.26.1)
pyxdg (0.25)
PyYAML (3.12)
rubber (1.4)
SecretStorage (2.3.1)
setuptools (39.0.1)
six (1.11.0)
wheel (0.30.0)
Now how do I fix the import error for DSS?
It looks like you also have pycrypto (2.6.1) installed which also has a module named Crypto.Signature. What is happening is that Python is trying to import pycrypto.Crypto.Signature (which does not have a DSS module) instead of pycryptodome.Crypto.Signature. To fix this you could try running
pip uninstall pycrypto and see if that fixes your issue.
Note on the install page for pycryptodome it says "One must avoid having both PyCrypto and PyCryptodome installed at the same time, as they will interfere with each other".

Categories

Resources