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

    Accessing librarys on SD card

    Scheduled Pinned Locked Moved WiPy 2&3
    wipywipy 1sdcard
    7 Posts 4 Posters 2.6k 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.
    • M Offline
      michalt38
      last edited by

      Hello,
      I want to access a mysql library which is on SD card but when I write: import mysql it says that this module could not be found. So how can I access this library?

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino @michalt38
        last edited by jmarcelino

        @michalt38
        As far as I know libraries have to be in the internal /flash/lib folder, you can put them there via FTP.

        However be aware that the standard Python MySQL library won't work in MicroPython as it's too resource heavy and has requirements such as the MySQL C libraries which aren't available here.

        Usually you'll do simple calls to a simpler web service/remote server which will have these libraries and access MySQL.

        sorenS 1 Reply Last reply Reply Quote 0
        • M Offline
          michalt38
          last edited by michalt38

          @jmarcelino
          Thanks for an answer. Do you have an example code that runs MySQL in a way you have described?

          1 Reply Last reply Reply Quote 0
          • sorenS Offline
            soren @jmarcelino
            last edited by

            @jmarcelino wait, does this mean that you can't use the SD card for extra library space? that makes it pretty useless if that's the case. I have mqtt, onewire and a few other small one-file libraries on the internal and I'm already out of space..

            robert-hhR 1 Reply Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @soren
              last edited by

              @soren The places used by import are listed in sys.path. The default value is ['', '/flash', '/flash/lib']. Once you have mounted the sd card, e.g. in /sd, you can issue:
              sys.path.append("/sd")
              sys.path.append("/sd/lib")
              Then it looks like ['', '/flash', '/flash/lib', '/sd', '/sd/lib']
              After that, scripts in /sd and /sd/lib are found by import.

              sorenS 1 Reply Last reply Reply Quote 1
              • sorenS Offline
                soren @robert-hh
                last edited by soren

                @robert-hh EDIT: nevermind, it's working now. Gotta remember to "mount" the sd card.

                ah cool, thank you robert! when i ftp into the lopy, i can't see the SD card - does this mean that formatting isn't correct or something else is wrong? I formatted it as FAT32 and named it LOPY

                robert-hhR 1 Reply Last reply Reply Quote 0
                • robert-hhR Offline
                  robert-hh @soren
                  last edited by

                  @soren You have to mount the SD card first, before you can see it in ftp. The format I'm using is FAT32. A sample mount sequence is below, taken from the docs.

                  #
                  import os
                  import machine
                  
                  sd = machine.SD()
                  os.mount(sd, '/sd')
                  
                  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