How to use "libpcre" on the Pycom MicroPython runtime?
andreas last edited by andreas
Dear Pycom Team,
First things first: Thanks for conceiving and building this wonderful platform. We are just getting started with MicroPython on the FiPy and had good experiences so far after resolving some minor obstacles we might report about later. For the records: We are running your build of
Pycom MicroPython 1.20.0.rc7as of 2019-02-08.
Now, after trying to incorporate the micropython-terkin library originally developed on MicroPython for Unix, we found that
re.pyerrors out on the FiPy by
File "dist-packages/urllib/parse.py", line 30, in <module> File "dist-packages/re.py", line 11, in <module> AttributeError: 'NoneType' object has no attribute 'func'
after we installed the
micropython -m upip install -p dist-packages micropython-urllib.parseand then uploading the
mkdir /flash/dist-packages rsync dist-packages /flash/dist-packages
pcre.funcis actually the first thing used after importing
pcre = ffilib.open("libpcre") # pcre *pcre_compile(const char *pattern, int options, # const char **errptr, int *erroffset, # const unsigned char *tableptr); pcre_compile = pcre.func("p", "pcre_compile", "sipps")
So, we are now wondering whether the
libpcrelibrary is available on the Pycom MicroPython runtime at all? As we haven't been able to find a reference to it on the documentation pages and on the forum yet, we found it appropriate to just ask here.
Thanks again and keep up the spirit.
With kind regards,
we resolved this issue and it is easy to tackle if you know what has been happening to make things go south. So, let me explain.
When installing micropython-urllib.parse with
upip, this obviously pulls in all package dependencies. One dependency, the package
micropython-re-pcrebrings in the
re.pymodule along with
ffilib.pyas a utility module to be able to talk to
However, all of this is not available on the Pycom platform, but Pycom itself ships a built-in
repackage, which would have worked right away when not being masked by the vanilla
So, we manually remove
dist-packagesfolder before uploading the firmware using
urllibwill use the built-in
re.pymodule and everything works like a charm.
Sorry for the noise and happy hacking,
P.S.: If you are interested in what we are building here, you are welcome to have a look at the Hiveeyes MPY data logger firmware. We'd love to hear about any feedback and suggestions you might have.
So, we conclude either micropython-urllib.urequest or micropython-urllib would be more appropriate than micropython-urllib.parse.
When looking at this again, we found the former just contains an
urlopenfunction, while the latter is committed as a dummy module and contains no code at all.
So, our question is still standing and we are humbly asking again for any hints how to get any official implementation of
urlencodeinto the MicroPython universe.
We are open to any option, either by somehow getting
libpcreinto the platform or by using an appropriate pure-Python module.
timh last edited by
@martinnn micropython for unix is just what it says. You can build micropython for any linux distribution. And its usually an installable option via opkg on openwrt based images. Which is a good scenario for it - small cut down python ;-)
Martinnn last edited by
MicroPython for Unix
Out of curiosity - what is micropython for unix? As I understand it, micropython is made for resource-limited microcontrollers and Unix is quite the opposite direction?
I assume you are aware of the pycom sources on github.
Looking at this from a different angle, we believe it would be more suitable to make the micropython-terkin library use another
urlliblibrary not based on the
micropython-re-pcremodule in order not to depend on OS-level bindings and reclaim pure-Python sanity ;].
So, we conclude either micropython-urllib.urequest or micropython-urllib would be more appropriate than micropython-urllib.parse. Bummer that we used the other one before not known about its system-level dependency to