ImportError for local code modules

  • Re: ImportError even module is in the same folder


    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 I have tried with the files in the same folder as 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 but that doesn't work either (I was half expecting that to work).

    Are there some settings I should adjust?


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

  • 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.

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

    import uos

    You should get a list of file names.

Log in to reply

Pycom on Twitter