Page 1 of 1

Python file can't import another py file

Posted: Mon Aug 05, 2019 3:41 am
by tim3385
I embed javascript port into my emscripten application. mp_js_do_str works fine in my c code.
And that pyexec_file invoke a python file is fine too. i.e. upy works in web application. But The python file can't "import" another module which is also a python file in the same directory.
I test it in emscripten MEMFS root directory "/".

This is the gist below(Sorry, I don't know how to insert text as code in this forum):
FILE* fp = NULL;
fp = fopen("", "w");
fprintf(fp, "import woxiao\nwoxiao.HUDPrint(\"print by\")\n");

fp = fopen("", "w");
//fprintf(fp, "import woxiao\nwoxiao.HUDPrint(\"print by\")\ntry:\nimport t2\nwoxiao.HUDPrint(\"+ import t2 done\")\npass\nexcept ImportError:\nwoxiao.HUDPrint(\"- import t2 failed\")\n");
fprintf(fp, "import woxiao\nwoxiao.HUDPrint(\"print by\")\nimport t2\n");

//pyexec_file (""); //works fine
pyexec_file (""); // can't import t2
ps. "woxiao.HUDPrint" is just a debug print function in my own "woxiao" module which is extended in my C code. And it works fine.