Ben
Ben

Reputation: 9703

Importing a module embedded in an executable's Python API?

I have an application that provides a nice Python API (Python3, FWIW). Using its GUI I can trigger Python scripts or use its Python shell. In the scripts I have it run, I can import the Foo module the vendor provides. What I'd like to do is import Foo from a stand-alone Python session. Is this possible? (Or does it depend on how it's implemented?)

I looked at sys.path in the interactive shell they provide but don't see anything relevant.

When the application spawns a Python interpreter, is it somehow injecting a module into it that can't be accessed from a stand-alone Python interpreter or is there a way to tell my Python interpreter to find Foo inside the application's executable?

For what it's worth:

>>> Foo
<module 'Foo' (built-in)>
>>>

Upvotes: 0

Views: 70

Answers (1)

babbageclunk
babbageclunk

Reputation: 8731

There's no guarantee that the module available within the application could be imported into a standalone script, especially if the API provides facilities for interacting with the running application. It's likely to be something that's provided by the way the Python interpreter is embedded in the application. See the documentation on embedding Python for how that might be done.

That said, it would be worth looking to see whether you can find a .pyd file (on Windows) or a .so file (on Unices) for the module somewhere in the application's files - it's possible that some of the functionality it provides could work without the running app.

Upvotes: 2

Related Questions