Issue
I have a c++ program which embeds python3.11.2. When calling a python script (which imports 3rd party modules as well as standard library modules) from embedded python i get the following error:
excType: 'AttributeError'
excValue: AttributeError("module 'abc' has no attribute '__file__'")
excTraceback: <traceback object at 0x7f1e48c5f200>
When i run the script from normal (non embedded) python, everything works fine and it is also able to locate the file attribute of the abc module.
I compiled python3.11.2 from source with the following configurations: --enable-optimizations --enable-shared --prefix="Path/To/My/Custom/Build/Folder/
Strange thing is that every 3rd party module that my script imports does have a file atttribute and loads fine.
Anybody got any insights on what could be causing this?
My OS: Ubuntu 22.04.3
I tested other standard library modules like os. If i call functions from os from embedded python it works fine, but the file attribute is not found for os. If i do this from non-embedded python it does find the file attribute.
Update: I just found out that embedded python has an empty prefix. How can i change this prefix? Setting PYTHONHOME doesn't change anything.
Solution
I found a workaround by adding the file attribute of the modules manually. I still don't get why the file attribute is not set by default, but this works for me now.
Answered By - roelv Answer Checked By - Senaida (WPSolving Volunteer)