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: PyModule_Create() doesn't add/import module
Type: behavior Stage:
Components: Extension Modules Versions: Python 3.0
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, blakemadden, brett.cannon
Priority: normal Keywords:

Created on 2008-12-09 15:41 by blakemadden, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg77428 - (view) Author: blake madden (blakemadden) Date: 2008-12-09 15:41
In reference to Issue4592 (which includes a patch),
PyModule_Create()calls PyModule_New instead of PyImport_AddModule. 
Because of this, calling PyModule_Create() won't work like Py_InitModule().

Is this correct, because the documentation is showing that
PyModule_Create() is all you need to use to create and add a module to
the system.  However, this is not the case.
msg77439 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-12-09 18:35
Are you returning the module in your extension's init function? The
import machinery takes the returned module from the init function and
adds it to sys.modules for you.
msg77442 - (view) Author: blake madden (blakemadden) Date: 2008-12-09 19:35
Sorry, mate, that's all Greek to me--I'm a total noob with Python.  I'm
simply trying to run the example in r67655 (the "Extending Embedded
Python" example) and it fails with "'emb' not being found".  It appears
that calling "PyModule_Create(&EmbModule);" is not enough to create and
import the library.

Somebody made a comment in Issue4592 that "PyModule_Create" was missing
some logic, so I'm reporting that here.

I honestly don't know if there is something wrong with "PyModule_Create"
or if the example is missing something.  I'm just trying to get this
example to work.
msg77447 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-12-09 20:56
Ah, I had not looked at the issue; sorry about the confusion.
PyImport_Create() is doing what it is supposed to be doing and should
not call PyImport_AddModule(). The example is wrong.

Closing this as invalid since the example is off.
msg77465 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-12-09 22:34
When python is embedded in a program, there must be a way for the 
program to export 
some of its functions to python - a module that resides in the main 
executable.

You cannot use the import machinery to import such a module, because 
there is no 
separate file to find and load. Instead, the embedding program 
explicitly calls the 
module init() function. 
With python 2.x, this creates the module *and* inserts it into 
sys.modules. Then 
subsequent imports will find it directly in sys.modules.

mod_python for example works this way.
I maintain that the sample is still valid, and should be made to work 
somehow.
msg77467 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-12-09 22:36
On Tue, Dec 9, 2008 at 14:34, Amaury Forgeot d'Arc
<report@bugs.python.org> wrote:
>
> Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment:
>
> When python is embedded in a program, there must be a way for the
> program to export
> some of its functions to python - a module that resides in the main
> executable.
>
> You cannot use the import machinery to import such a module, because
> there is no
> separate file to find and load. Instead, the embedding program
> explicitly calls the
> module init() function.
> With python 2.x, this creates the module *and* inserts it into
> sys.modules. Then
> subsequent imports will find it directly in sys.modules.
>
> mod_python for example works this way.
> I maintain that the sample is still valid, and should be made to work
> somehow.

That's what I mean; the example is off as in incorrect. Not off as in
trying to do something silly.
msg77468 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-12-09 22:44
OK. I'm currently writing a documentation patch for issue4592.
History
Date User Action Args
2022-04-11 14:56:42adminsetgithub: 48862
2008-12-09 22:44:15amaury.forgeotdarcsetmessages: + msg77468
2008-12-09 22:36:33brett.cannonsetmessages: + msg77467
2008-12-09 22:34:19amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg77465
2008-12-09 20:56:20brett.cannonsetstatus: pending -> closed
resolution: not a bug
messages: + msg77447
2008-12-09 19:35:58blakemaddensetmessages: + msg77442
2008-12-09 18:35:32brett.cannonsetstatus: open -> pending
2008-12-09 18:35:05brett.cannonsetnosy: + brett.cannon
messages: + msg77439
2008-12-09 15:41:10blakemaddencreate