micropython-lib icon indicating copy to clipboard operation
micropython-lib copied to clipboard

AttributeError: 'NoneType' object has no attribute 'func'

Open nick-0307 opened this issue 5 years ago • 9 comments

When I import multiprocessing, there is an error saying that:
File "main.py", line 5, in File "multiprocessing.py", line 3, in File "select.py", line 14, in AttributeError: 'NoneType' object has no attribute 'func'

Would you please help me solve this problem?

nick-0307 avatar Jun 27 '20 09:06 nick-0307

I get the same with the base64 module:

>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "/lib/base64.py", line 9, in <module>
  File "/lib/re.py", line 11, in <module>
AttributeError: 'NoneType' object has no attribute 'func'

kitplummer avatar Sep 06 '22 17:09 kitplummer

In both cases here the ffi modules for select and re respectively have been installed, but they can't find the referenced dynamic libraries.

@kitplummer if you see re.py", line 11, in https://github.com/micropython/micropython-lib/blob/f3cfc52ab076fc913dc6e266fb7370b418c8f542/unix-ffi/re/re.py#L11 it's clear pcre is None meaning the ffi command earlier couldn't find it https://github.com/micropython/micropython-lib/blob/f3cfc52ab076fc913dc6e266fb7370b418c8f542/unix-ffi/re/re.py#L6

andrewleech avatar Sep 06 '22 20:09 andrewleech

@jimmo would it make most sense for ffilib.open() raise an exception if it can't find the library?

andrewleech avatar Sep 06 '22 20:09 andrewleech

@andrewleech - thanks, eventually dug in enough to find that being the issue.

I'm working with a Raspberry Pico W, which apparently doesn't have the lib. :) Working around it now, but that might be worth adding to make it obviously clear.

kitplummer avatar Sep 06 '22 20:09 kitplummer

Ah yes, the ffi based libs only work on Linux.

How did you install these libraries out of interest?

This repo is in the process of being reorganised a bit with the recent manifest file charges, working towards making library compatibility and installation easier and more reliable.

andrewleech avatar Sep 06 '22 20:09 andrewleech

I installed with upip.

kitplummer avatar Sep 06 '22 21:09 kitplummer

For posterity, I was trying to use urllib.parse for urlencode purposes - which pulls in micropython-re-pcre (and the ffilib dep) by default.

kitplummer avatar Sep 06 '22 21:09 kitplummer

Ah thanks, that context definitely helps! urllib.parse is definitely something I can see as useful on rpi-w / networked boards, it'd be worth updating it to work with the built-in re module.

andrewleech avatar Sep 06 '22 21:09 andrewleech

Should've mentioned, the quick-fix for me was to simply delete the re.py and ffilib.py files from the Pico's lib/ subdir - and using the built-in stuff.

kitplummer avatar Sep 07 '22 21:09 kitplummer