import custom "module" - file location?

Discussion related to "under the hood" OpenMV topics.
type11969
Posts: 30
Joined: Tue Aug 14, 2018 1:03 pm

import custom "module" - file location?

Postby type11969 » Mon Oct 22, 2018 8:57 pm

Greetings. Apologies in advance, I have some C programming background but I am a complete newbie to python. I am trying to do something simple - I'm trying to organize my project in to separate files much like I usually do with my C based projects. But for whatever reason, I cannot get the "import" functionality to work for a file I've created. I suspect that it has something to do with my file location or something simple I am missing in a file header, etc. I have a basic file named test.py with a simple function in it (note that the excerpt below is literally all I have in the file).

Code: Select all

def testFunction:
    print("test")
In the same directory, I have another simple file named test_main:

Code: Select all

import sensor, image, time, test

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    print(clock.fps())
When I try to run test_main, I get an ImportError: No module named 'test'.

Both files are in the same directory. Originally they were not in the OpenMV folder in "mydocuments", but I tried relocating them there with no success. So what am I missing? Has to be something simple/stupid. My understanding is that per ~feb of this year, the openmv ide supported importing like this - am I mistaken?

Rapid feedback appreciated - thanks!

-Chris
User avatar
kwagyeman
Posts: 2401
Joined: Sun May 24, 2015 2:10 pm

Re: import custom "module" - file location?

Postby kwagyeman » Tue Oct 23, 2018 1:47 am

The OpenMV Cam compiles the code so the test.py file had to be on its flash drive. OpenMV IDE doesn't actually do anything other than act as an editor and debug window.

That said, the IDE is quite smart and if you have that test.py file in the OpenMV folder in my documents OpenMV IDE will find it and ask if you'd like to copy it to the camera.
Nyamekye,
type11969
Posts: 30
Joined: Tue Aug 14, 2018 1:03 pm

Re: import custom "module" - file location?

Postby type11969 » Tue Oct 23, 2018 2:50 pm

Thanks. If I make a change to test.py, I do get prompted with the following - Module test on your OpenMV Cam is different than the copy on your computer. Would you like OpenMV IDE to update the module on your Open MV Cam?
If I click yes, I then get the same error - ImportError: no module named 'test'.
So its odd, OpenMV can find the test.py file, but there is still some sort of import error. Any ideas?
User avatar
kwagyeman
Posts: 2401
Joined: Sun May 24, 2015 2:10 pm

Re: import custom "module" - file location?

Postby kwagyeman » Tue Oct 23, 2018 5:13 pm

Can you confirm the test.py module was copied over to your OpenMV Cam's disk? Note that windows caches writes so it make take a second for the file to actually make it to the device.
Nyamekye,
type11969
Posts: 30
Joined: Tue Aug 14, 2018 1:03 pm

Re: import custom "module" - file location?

Postby type11969 » Tue Oct 23, 2018 5:49 pm

Just to confirm, "disk" is referring to the folder that pops up upon physical USB connection, correct? If so, then no, I do not see test.py carried over to this folder. In fact, if I use the "save open script to openMV cam" command, I don't see test_main.py saved to this folder either. So apparently the problem is deeper than I thought. What would be preventing file transfer to the OpenMV cam? Certainly I can run new scripts through the IDE without issue.

Thanks for the help!

-Chris
User avatar
kwagyeman
Posts: 2401
Joined: Sun May 24, 2015 2:10 pm

Re: import custom "module" - file location?

Postby kwagyeman » Thu Oct 25, 2018 4:42 pm

Hmm, I think the IDE then has bound itself to the wrong disk. In the next firmware release we bind the IDE to a particular disk name.

So, check the drive in OpenMV IDE (on the status bar) that OpenMV IDE thinks is the disk. It mostly guessed wrong.

In the next release we've made this better.
Nyamekye,
type11969
Posts: 30
Joined: Tue Aug 14, 2018 1:03 pm

Re: import custom "module" - file location?

Postby type11969 » Mon Oct 29, 2018 5:02 pm

Thanks, I moved to my backup OpenMV cam which didn't have the same issue, I'll check the drive the next time I use the other cam.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 7 guests