Chromebook: Python serial error

I have been using PlatformIO to upload successfully to Arduino boards on a couple of different Ubuntu Linux machines. However today when I installed on Ubuntu running on my Chromebook (via crouton) I get an error when I run

pio serialports list

Error: Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/platformio/__main__.py", line 107, in main
    cli(None, None, None)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/platformio/commands/serialports.py", line 40, in serialports_list
    for item in get_serialports():
  File "/usr/local/lib/python2.7/dist-packages/platformio/util.py", line 290, in get_serialports
    for p, d, h in comports():
  File "/usr/lib/python2.7/dist-packages/serial/tools/list_ports_posix.py", line 122, in comports
    return [(d, describe(d), hwinfo(d)) for d in devices]
  File "/usr/lib/python2.7/dist-packages/serial/tools/list_ports_posix.py", line 93, in describe
    return usb_lsusb_string(sys_usb)
  File "/usr/lib/python2.7/dist-packages/serial/tools/list_ports_posix.py", line 80, in usb_lsusb_string
    return base

and when I try and upload

sudo pio -t upload

I get error:

scons: *** [upload] NameError : global name 'base' is not defined
Traceback (most recent call last):
File "/home/glyn/.platformio/packages/tool-scons/script/../engine/SCons/Action.py", line 1063, in execute
result = self.execfunction(target=target, source=rsources, env=env)
File "/usr/local/lib/python2.7/dist-packages/platformio/builder/scripts/atmelavr.py", line 49, in BeforeUpload
env.AutodetectUploadPort()
File "/home/glyn/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 224, in __call__
return self.method(*nargs, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/platformio/builder/tools/pioupload.py", line 125, in AutodetectUploadPort
env.Replace(UPLOAD_PORT=_look_for_serial_port())
File "/usr/local/lib/python2.7/dist-packages/platformio/builder/tools/pioupload.py", line 100, in _look_for_serial_port
for item in util.get_serialports():
File "/usr/local/lib/python2.7/dist-packages/platformio/util.py", line 290, in get_serialports
for p, d, h in comports():
File "/usr/lib/python2.7/dist-packages/serial/tools/list_ports_posix.py", line 122, in comports
return [(d, describe(d), hwinfo(d)) for d in devices]
File "/usr/lib/python2.7/dist-packages/serial/tools/list_ports_posix.py", line 93, in describe
return usb_lsusb_string(sys_usb)
File "/usr/lib/python2.7/dist-packages/serial/tools/list_ports_posix.py", line 80, in usb_lsusb_string
return base
NameError: global name 'base' is not defined

I am running pyserial==3.1.1, full freeze output:

adium-theme-ubuntu==0.3.4
apt-xapian-index==0.45
backports-abc==0.4
backports.ssl-match-hostname==3.5.0.1
bottle==0.12.9
certifi==2016.2.28
cffi==1.6.0
chardet==2.0.1
click==5.1
colorama==0.3.7
command-not-found==0.3
cryptography==1.4
debtagshw==0.1
defer==1.0.6
derpconf==0.7.3
dirspec==13.10
enum34==1.1.6
esptool==0.1.0
futures==3.0.5
gyp==0.1
html5lib==0.999
httplib2==0.8
idna==2.1
ipaddress==1.0.16
libthumbor==1.3.1
lockfile==0.12.2
lxml==3.3.3
Nautilus-scripts-manager==1.7
ndg-httpsclient==0.4.1
numpy==1.8.2
oauthlib==0.6.1
oneconf==0.3.7.14.4.1
openshot==1.4.3
PAM==0.4.2
pexif==0.15
pexpect==3.1
Pillow==2.3.0
piston-mini-client==0.7.5
platformio==2.10.1
Pmw==1.3.2
pyasn1==0.1.9
pycparser==2.14
pycrypto==2.6.1
pycups==1.9.66
pycurl==7.19.3
pygobject==3.12.0
pyOpenSSL==16.0.0
pyserial==3.1.1
pysmbc==1.0.14.1
python-apt===0.9.3.5ubuntu2
python-debian===0.1.21-nmu2ubuntu2
python-magic==0.4.11
pytz==2016.4
pyxdg==0.25
reportlab==3.0
requests==2.10.0
sessioninstaller==0.0.0
singledispatch==3.4.0.3
six==1.10.0
software-center-aptd-plugins==0.0.0
statsd==3.2.1
system-service==0.1.6
tornado==4.3
Twisted-Core==13.2.0
Twisted-Web==13.2.0
unity-lens-photos==1.0
uptime==3.0.1
urllib3==1.7.1
wxPython==3.0.1.1
wxPython-common==3.0.1.1
xdiagnose===3.6.3build2
xmltodict==0.10.1
zope.interface==4.0.5

This seems to be the latest pyserial package version.

I have installed the udev rules. My serial device is as follows:

[68760.133280] usb 1-2: Product: FT232R USB UART
[68760.133292] usb 1-2: Manufacturer: FTDI
[68760.133303] usb 1-2: SerialNumber: A700ejYh
[68760.136203] ftdi_sio 1-2:1.0: FTDI USB Serial Device converter detected
[68760.136294] usb 1-2: Detected FT232RL
[68760.136306] usb 1-2: Number of endpoints 2
[68760.136319] usb 1-2: Endpoint 1 MaxPacketSize 64
[68760.136331] usb 1-2: Endpoint 2 MaxPacketSize 64
[68760.136343] usb 1-2: Setting MaxPacketSize 64
[68760.136713] usb 1-2: FTDI USB Serial Device converter now attached to ttyUSB9

Have you seen this error before? Any idea what I can try?

Does this command work for you?

$ python -m serial.tools.list_ports

If you see the same errors, please report an issue here Issues · pyserial/pyserial · GitHub

With no programmers or boards plugged in I get

python -m serial.tools.list_ports
/dev/ttyS0          
/dev/ttyS1          
/dev/ttyS2          
/dev/ttyS3          
4 ports found

Then when I plug in my programmer which gets attached to ttyUSB0, see dmesg outout:

[ 4088.929281] usb 1-1: new full-speed USB device number 14 using xhci_hcd
[ 4089.095409] usb 1-1: New USB device found, idVendor=10c4, idProduct=ea60
[ 4089.095432] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 4089.095490] usb 1-1: Product: CP2102 USB to UART Bridge Controller
[ 4089.095510] usb 1-1: Manufacturer: Silicon Labs
[ 4089.095525] usb 1-1: SerialNumber: 0001
[ 4089.251907] usb 1-1: reset full-speed USB device number 14 using xhci_hcd
[ 4089.404952] usb 1-1: reset full-speed USB device number 14 using xhci_hcd
[ 4089.557904] usb 1-1: reset full-speed USB device number 14 using xhci_hcd
[ 4089.570905] usb 1-1: cp210x converter now attached to ttyUSB0

Now when I run serial port list I get the same global name 'base' is not defined error :frowning: :

python -m serial.tools.list_ports
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/lib/python2.7/dist-packages/serial/tools/list_ports.py", line 99, in <module>
    main()
  File "/usr/lib/python2.7/dist-packages/serial/tools/list_ports.py", line 83, in main
    iterator = sorted(comports())
  File "/usr/lib/python2.7/dist-packages/serial/tools/list_ports_posix.py", line 122, in comports
    return [(d, describe(d), hwinfo(d)) for d in devices]
  File "/usr/lib/python2.7/dist-packages/serial/tools/list_ports_posix.py", line 93, in describe
    return usb_lsusb_string(sys_usb)
  File "/usr/lib/python2.7/dist-packages/serial/tools/list_ports_posix.py", line 80, in usb_lsusb_string
    return base
NameError: global name 'base' is not defined

This is obviously a python serial error rather than a PIO issue, but do you know anything I could try to fix?

Thanks a lot

Have you seen this blog post?

@glynhudson this is a bug of PySerial. Please report it here Issues · pyserial/pyserial · GitHub

Thanks @valeros! Manually applying fix #26 fixed the issue :smiley:. This fix was apparently merged in 2011 :astonished:, but it wasn’t present on my system running pyserial 3.1.1

I have reported the issue to pyserial:

Thanks for your help, onwards nd upwards :thumbsup: