Adding Modules
-
Hi All,
Having some trouble adding modules to my LoPy (with Expansion Board 2.0). In particular, one I am trying to add is (u)requests. If I take the urequests folder from https://github.com/micropython/micropython-lib and throw it in /flash/lib, I can import it, but urequests.<anything> (like urequests.get()) doesn't work, and dir(urequests) gives name and file only. Same thing if I put it on the micro sd card (with it mounted as /sd/ and that added to sys.path).
Rather than the folder itself, if I paste the files from inside it into /flash/lib, dir(urequests) shows all of urequest's functions. While this lets me use it, it doesn't let me add other modules, as they'll each have a setup.py.
Do I need to add the folder from each module I add to sys.path (e.g. /flash/lib/urequests, /flash/lib/ssl, ..., etc.)? I have searched around quite a bit and didn't see anything saying that is the right way to do it. On the contrary, the first way I tried seemed to be the prescribed method.
Thank you for the assistance.
-
@cpyree I tried to add a tests folder and put files in there. I did something like this
# Add test dir path sys.path.insert(0, "/test") import test_xSadly this failed. Any idea how to do something like this?
-
@netskink the following command works for me though:
import sys sys.path.append("/flash/test") import test_x@cpyree, the copy of the urequests forlder in /flash/lib is correct. May be, since the urequests forlder does not have _init_.py file, you need to import it as:
import urequests.urequests as urequests urequests.get(...)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login