Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4d4b19e

Browse files
committed
Document that packaging doesn’t create __init__.py files (#3902).
The bug reported expected distutils to create an __init__.py file for a project using only C extension modules. IMO, how Python imports packages and submodules is well documented, and it’s never suggested that distutils might create an __init__.py file, so I’m adding this clarification to the packaging docs but won’t backport unless other people tell me they shared the same wrong expectation. Thanks to Mike Hoy for his help with the patch.
1 parent f89ebdc commit 4d4b19e

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

Doc/library/packaging.compiler.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,3 +675,7 @@ extension modules.
675675
| | abort the build process, but | |
676676
| | simply skip the extension. | |
677677
+------------------------+--------------------------------+---------------------------+
678+
679+
To distribute extension modules that live in a package (e.g. ``package.ext``),
680+
you need to create you need to create a :file:`{package}/__init__.py` file to
681+
let Python recognize and import your module.

Doc/packaging/setupscript.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ resulting object code are identical in both cases; the only difference is where
177177
in the filesystem (and therefore where in Python's namespace hierarchy) the
178178
resulting extension lives.
179179

180+
If your distribution contains only one or more extension modules in a package,
181+
you need to create a :file:`{package}/__init__.py` file anyway, otherwise Python
182+
won't be able to import anything.
183+
180184
If you have a number of extensions all in the same package (or all under the
181185
same base package), use the :option:`ext_package` keyword argument to
182186
:func:`setup`. For example, ::

0 commit comments

Comments
 (0)