Python issue with BoM script

Hi there,

I’ve adapted one of the bom scripts to suit my needs. When I run it from eschema “Bill of Material” / Generate, it fails on importing a digikey module with

Command error. Return code 1.
Traceback (most recent call last):
  File "/home/scott/.local/share/kicad/6.0/plugins/bom.py", line 26, in <module>
    import digikey
  File "/home/scott/.local/lib/python3.10/site-packages/digikey/__init__.py", line 1, in <module>
    from digikey.v3.api import (keyword_search, product_details, digi_reel_pricing, suggested_parts,
  File "/home/scott/.local/lib/python3.10/site-packages/digikey/v3/api.py", line 4, in <module>
    import digikey.oauth.oauth2
  File "/home/scott/.local/lib/python3.10/site-packages/digikey/oauth/oauth2.py", line 14, in <module>
    from certauth.certauth import CertificateAuthority
  File "/home/scott/.local/lib/python3.10/site-packages/certauth/certauth.py", line 6, in <module>
    from OpenSSL import crypto
  File "/usr/local/lib/python3.10/dist-packages/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import SSL, crypto
  File "/usr/local/lib/python3.10/dist-packages/OpenSSL/SSL.py", line 19, in <module>
    from OpenSSL.crypto import (
  File "/usr/local/lib/python3.10/dist-packages/OpenSSL/crypto.py", line 3253, in <module>
    utils.deprecated(
TypeError: deprecated() got an unexpected keyword argument 'name'

The script works perfectly in vscode and the command line. I’ve confirmed i’m using the same /usr/bin/python to run. I can import the digikey module by running python on the cli,

$ python
Python 3.10.7 (main, Nov 24 2022, 19:45:47) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import digikey
>>> 

but I fail from KiPython.

Py 0.9.8
Python 3.10.7 (main, Nov 24 2022, 19:45:47) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
import digikey
Traceback (most recent call last): <snip>

Is there an environment variable somewhere that I haven’t found yet, or a sandbox which isnt configured right?

This is KiCad 6.0.10, running on Ubuntu 22.10

Cheers,
Scott

That’s a distro issue and not kicad or digikey.

It sounds like you need to force pip to try and upgrade pyOpenSSL or some people have success uninstalling it.

Hi Marekr, thanks for the reply.

If it was a distro issue wouldn’t it also fail when run from the command line?

Cheers,
Scott

:shrug:

You can search that exact error, the pyopenssl package is at fault, either there’s a bad bundled version or the distro has duplicated python openssl packages

:shrug: indeed!

I don’t understand why it didn’t run in the kicad environment, but

pip uninstall pyopenss
sudo pip uninstall pyopenss
sudo apt install python3-openssl

and now it works from within kicad.

Of course it no longer works from the command line, but if everything always worked perfectly life would be boring…

The location /usr/ocal/lib/python3.10 suggests that you did a sudo pip install pyopenssl at some point in the past since /usr/local is not a normal destination for distro packages. Perhaps many distro versions ago since /usr/local is preserved across upgrades.

You’re right - bash history shows that for no reason at all I did

  958  pip install digikey-api
  959  sudo pip install digikey-api

I removed the sudo version of digikey-api and tried with the non-sudo pip install pyopenssl again. Same result (works from cli, not from kicad)

I have a work around now (install system package to work in kicad, install pip package to work from vscode/cli) so although it’s annoying I have a path forwards.

Still curious why the different behaviour tho!

Probably because your CLI invocation doesn’t search in your ~/.local for modules. You didn’t show what happened in that case, was digikey module missing?

Good point, please see the failure mode below. It does appear to look in ~/.local, from the line
File "/home/scott/.local/lib/python3.10/site-packages/digikey/__init__.py", line 1, in <module>

BoM$ /bin/python /home/scott/.local/share/kicad/6.0/plugins/bom.py KicadProject-*.xml ./Idle.csv
Traceback (most recent call last):
  File "/home/scott/.local/share/kicad/6.0/plugins/bom.py", line 26, in <module>
    import digikey
  File "/home/scott/.local/lib/python3.10/site-packages/digikey/__init__.py", line 1, in <module>
    from digikey.v3.api import (keyword_search, product_details, digi_reel_pricing, suggested_parts,
  File "/home/scott/.local/lib/python3.10/site-packages/digikey/v3/api.py", line 4, in <module>
    import digikey.oauth.oauth2
  File "/home/scott/.local/lib/python3.10/site-packages/digikey/oauth/oauth2.py", line 14, in <module>
    from certauth.certauth import CertificateAuthority
  File "/home/scott/.local/lib/python3.10/site-packages/certauth/certauth.py", line 6, in <module>
    from OpenSSL import crypto
  File "/usr/lib/python3/dist-packages/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import crypto, SSL
  File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 3279, in <module>
    _lib.OpenSSL_add_all_algorithms()
AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.