This seems to be a quirk? of the unix version of micropython. I was able to reproduce this by creating a file iceCream.py that contained:
and copying that into the modules directory and rebuilding micropython. As you did, I get:
Code: Select all
637 >./micropython
MicroPython v1.10-290-g8402c26cf-dirty on 2019-04-30; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import iceCream
Executing iceCream.py
>>>
and with a main.py that contained:
then I get:
Code: Select all
637 >./micropython main.py
Traceback (most recent call last):
File "main.py", line 4, in <module>
ImportError: no module named 'iceCream'
The next thng I did was to print sys.path for each of these cases:
Code: Select all
638 >./micropython
MicroPython v1.10-290-g8402c26cf-dirty on 2019-04-30; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import sys
>>> print(sys.path)
['', '/home/dhylands/.micropython/lib', '/usr/lib/micropython']
>>>
and
Code: Select all
640 >./micropython main.py
['/home/dhylands/Dropbox/micropython/micropython/ports/unix', '/home/dhylands/.micropython/lib', '/usr/lib/micropython']
Traceback (most recent call last):
File "main.py", line 4, in <module>
ImportError: no module named 'iceCream'
and this shows us the difference. The empty string in sys.path is where the interpreter will look for frozen modules, and when executing main.py there is no empty path added to sys.path. If we add it ourselves:
Code: Select all
import sys
sys.path.insert(0, '')
print(sys.path)
import iceCream
then everything works as expected:
Code: Select all
646 >./micropython main.py
['', '/home/dhylands/Dropbox/micropython/micropython/ports/unix', '/home/dhylands/.micropython/lib', '/usr/lib/micropython']
Executing iceCream.py