0

I'm writing library to another .exe program, and want to import .py file from qt resource. I'm usually using 'PyRun_SimpleString' but i have problem because i don't want copy my file to disc, just import it from resource.

I tried change path by sys.path.insert to resource path then use PyRun_SimpleString to call 'import calculator' but this didn't work for me.

PyRun_SimpleString("code = ''import sys\nsys.path.insert(0, ':/Python/'\nimport calculator'");
PyRun_SimpleString("exec(code)");

I tried with qrc path too and every time i have one result from main .exe program ImportError No module named calculator

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • I cannot imagine that Python can resolve Qt resource paths. Instead (I believe) you have to read file contents from Qt resource and then call `PyRun_SimpleString()` with it. However, I would store the text of Python in a string and call this with `PyRun_SimpleString()`. Conversion of python source file to a C++ variable definition could be done with a small self-written tool, similar like sketched in my answer to [SO: How to include data object files (images, etc.) in program and access the symbols?](https://stackoverflow.com/a/47415163/7478597). – Scheff's Cat Jul 20 '19 at 14:18
  • Concerning _read file contents from Qt resource_ I found this: [Qt Forum: Using a text file as resource of the project](https://forum.qt.io/topic/72994/using-a-text-file-as-resource-of-the-project/4). – Scheff's Cat Jul 20 '19 at 14:20

0 Answers0