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

    Use external libraries

    Scheduled Pinned Locked Moved LoPy
    4 Posts 4 Posters 2.3k 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.
    • I Offline
      iber
      last edited by

      Where can I find documentation for using/importing other libraries on my LoPy.
      I want to use the Paho MQTT Python library. Should I put it somewhere in the /flash over ftp?

      I'm new to Pycom and the Python programming language but I'm an experienced developer in Java, C++, Arduino,... So if you can point me to any other valuable info to get me started please share!

      Thx in advance!

      1 Reply Last reply Reply Quote 0
      • L Offline
        lmn
        last edited by

        Library is just another python file. If you put library.py into the same folder as the main.py you can than import it in the main.py file like this:

        import library

        and use objects in the library:

        library.ExampleClass()

        python docs

        1 Reply Last reply Reply Quote 0
        • R Offline
          rskoniec
          last edited by rskoniec

          I think that /flash/lib folder is also right and logical place for external libraries. ;o)

          The machine is working as good as it's code.

          1 Reply Last reply Reply Quote 2
          • B Offline
            betabrain
            last edited by

            Note that /flash and /flash/lib are in sys.path by default. If you want to put your libraries somewhere else, don't for get to add that directory to your path in boot.py.

            import sys
            sys.path.append('/flash/custom-dir')
            
            1 Reply Last reply Reply Quote 1

            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