ImportError for local code modules
-
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
-
@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.
-
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 Glad to here it's working now :)
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