Skip to content

Python file can't import another py file #4972

@fei2020

Description

@fei2020

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:

	FILE* fp = NULL;
	fp = fopen("t2.py", "w");
	fprintf(fp, "import woxiao\nwoxiao.HUDPrint(\"print by t2.py\")\n");
	fclose(fp);

	fp = fopen("t1.py", "w");
	//fprintf(fp, "import woxiao\nwoxiao.HUDPrint(\"print by t1.py\")\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 t1.py\")\nimport t2\n");
	fclose(fp);

	//pyexec_file ("t2.py");  //works fine
	pyexec_file ("t1.py");  // 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy