Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Adding Modules

    Scheduled Pinned Locked Moved Discussion
    librarylopy
    3 Posts 3 Posters 904 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C Offline
      cpyree
      last edited by

      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.

      N 1 Reply Last reply Reply Quote 0
      • N Offline
        netskink @cpyree
        last edited by

        @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_x
        

        Sadly this failed. Any idea how to do something like this?

        1 Reply Last reply Reply Quote 0
        • N Offline
          nftylitak
          last edited by

          @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(...)
          
          1 Reply Last reply Reply Quote 0

          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
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom