This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: frozen importlib required for extending Python interpreter not public
Type: behavior Stage:
Components: None Versions: Python 3.3
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, atuining, brett.cannon, eric.snow, jcea, r.david.murray, takluyver
Priority: normal Keywords:

Created on 2012-11-13 18:33 by atuining, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg175515 - (view) Author: Anthony Tuininga (atuining) * Date: 2012-11-13 18:33
With Python 3.3, the ability to create a Python interpreter independent of a Python installation (as is done with cx_Freeze and other such freezing tools) has become more difficult to accomplish. Py_Initialize() requires the presence of a frozen importlib module which is found in importlib.h, but that include file is not available in the public include files section of a Python distribution. I have copied it for my use but that seems wrong. Please advise on how this should take place now. Thanks.
msg175516 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-11-13 18:38
The file certainly exists, since Python requires it to run.  It sounds like cx_Freeze just doesn't support Python3.3 yet.  I don't see that this is a Python bug.
msg175519 - (view) Author: Anthony Tuininga (atuining) * Date: 2012-11-13 19:03
The file importlib.h is used when building the Python interpreter but it is *not* available in a standard (non-source) distribution of Python. I have copied the file from a source distribution of Python and that does in fact work, but I don`t want to make use of what is intended to be a private implementation detail. I am the author of cx_Freeze and trying to make it work correctly with Python 3.3. What I am looking for here is what I should be doing instead or asking for API that I can use. I hope that explains things better.
msg175521 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2012-11-13 20:09
I tried to remove all references to "#include importlib.h" and _Py_M__importlib, and added the lines in _AddBaseModules():

    self.AddAlias("_frozen_importlib", "importlib._bootstrap")
    self.IncludeModule("_frozen_importlib")

Even if it's not optimal (the content importlib.h is recomputed by cx_Freeze), it's much better...  The resulting binary I made fails with:
  Fatal Python error: Py_Initialize: Unable to get the locale encoding
  ImportError: No module named 'encodings'
But it's probably because my Python3 is not "installed" properly.
msg175535 - (view) Author: Anthony Tuininga (atuining) * Date: 2012-11-14 05:31
Thanks to Amaury for his suggestion. It resolves the problem completely and answers the question I had about how to proceed. For others who may come across this, the key was to generate the importlib._bootstrap module (which is what is found in importlib.h) directly, rather than by including the private generated file.
History
Date User Action Args
2022-04-11 14:57:38adminsetgithub: 60671
2012-11-29 21:40:23jceasetnosy: + jcea
2012-11-14 05:31:54atuiningsetstatus: open -> closed

messages: + msg175535
2012-11-14 00:11:22eric.snowsetnosy: + brett.cannon, eric.snow
2012-11-13 22:23:14takluyversetnosy: + takluyver
2012-11-13 20:09:05amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg175521
2012-11-13 19:03:37atuiningsetmessages: + msg175519
2012-11-13 18:38:43r.david.murraysetnosy: + r.david.murray
messages: + msg175516
2012-11-13 18:33:14atuiningcreate