← index #3509PR #262
Related · medium · value 1.677
QUERY · ISSUE

Mpy modules cannot be imported (sys.path missing '') when running file outside of cwd

openby ryannathansopened 2017-12-21updated 2021-12-17
py-core

Found on unix port - protostuffer is a single .py file in the modules folder, built in at compile time

./micropython
MicroPython v1.9.3-7-g46e9ef6-dirty on 2017-12-21; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import protostuffer
>>>
./micropython ../../tests/protostuffer-tests/header.py
Traceback (most recent call last):
  File "../../tests/protostuffer-tests/header.py", line 1, in <module>
ImportError: no module named 'protostuffer'

To fix

./micropython -i ../../tests/protostuffer-tests/header.py
Traceback (most recent call last):
  File "../../tests/protostuffer-tests/header.py", line 1, in <module>
ImportError: no module named 'protostuffer'
MicroPython v1.9.3-7-g46e9ef6-dirty on 2017-12-21; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import protostuffer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'protostuffer'
>>> import sys
>>> sys.path.append('')
>>> import protostuffer
>>>
CANDIDATE · PULL REQUEST

Implement sys.path support

mergedby pfalconopened 2014-02-05updated 2014-06-14

This implement sys.path support - handling on __import__()'s side, and initialization of sys.path value for unix port. Adding needed changes for stm should be more or less trivial based on the unix code. There may be opportunities for refactoring and reusing some code. But I just wanted to put up this for review.

And some comments about patches: yeah, nobody likes to do string processing in C, especially if without dynamic memory alloc. But someone needs to overcome that and try ;-).

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied