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

    ImportError for local code modules

    Scheduled Pinned Locked Moved SiPy
    importerror
    4 Posts 3 Posters 369 Views 3 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
      ChangedDaily
      last edited by

      Re: ImportError even module is in the same folder

      Hi,

      I am just trying to make a start on my first Pycom project and I added a couple of code files (.py) and tried to import them into main.py. I have tried with the files in the same folder as main.py and the /lib folder. Neither will work, I just get "ImportError" message. I have investigated a little and I think it may be related to the sys.path which is set as follows:
      ['', '/flash', '/flash/lib'] which is what you would expect on the device itself but not in the project folder. I have tried uploading to the device as well as just trying to run the main.py but that doesn't work either (I was half expecting that to work).

      Are there some settings I should adjust?

      Thanks

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

        @changeddaily '' tells to expect the files in the same folder. If you have a file called sample.py, import sample should find that. Are you sure that the files are on the device? in REPL, what is the result of:

        import uos
        uos.listdir()
        

        You should get a list of file names.

        1 Reply Last reply Reply Quote 1
        • C Offline
          ChangedDaily
          last edited by

          Thank you Robert-hh. That has helped me get to the bottom of the problem. The directory structure on the module was not correct. I had been following an example which had a 'scripts' folder which was messing things up. Using the listdir() method quickly showed this up. I am also using FTP to connect and browse the directory structure on the device but I hadn't looked at that last night.

          All working now.

          P 1 Reply Last reply Reply Quote 0
          • P Offline
            Paul Thornton @ChangedDaily
            last edited by

            @changeddaily Glad to here it's working now :)

            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