简体   繁体   中英

"Package init file not found (or not a regular file)" - error when building sdist for namespace package

I have a namespace package with folder structure as: CompanyName\\DepartmentName\\SubDepartmentName\\PkgName

Python 3.3 onwards supports namespace packages so I have not place the __init__.py files in the following folders:

CompanyName
DepartmentName
SubDepartmentName

In the setup.py I have place the following piece of code setuptools.find_namespace_packages() instead of setuptools.find_packages() .

When I try to build the sdist, using the following commands:

python -m pip install --upgrade pip
python -m pip install --upgrade setuptools wheel
python setup.py sdist

I get the following error:

package init file 'CompanyName\__init__.py' not found (or not a regular file)
package init file 'CompanyName\DepartmentName\__init__.py' not found (or not a regular file)
package init file 'CompanyName\DepartmentName\SubDepartmentName\__init__.py' not found (or not a regular file)

I have the task setup as part of azure devops pipeline's command line task and have set 'Fail on standard error' to true. The pipeline fails due to the above error.

Though Package init file not found (or not a regular file) is more like a warning than an error locally, it will cause the build pipeline to fail if you set Fail on standard error to true when using VSTS.

Locally:

在此处输入图片说明

VSTS with Fail on standard error to default false:

在此处输入图片说明

VSTS with Fail on standard error to true:

在此处输入图片说明

1.For this, you can choose to turn-off the option( Fail on standard error ) cause the python namespace package can be generated successfully though that message occurs. So in this situation, I think you can suppress that message.

2.Also, another direction is to resolve the message when generating the package. Since the cause of the message has something to do with your definitions in your setup.py file, you should use setuptools.find_namespace_packages() like this document suggests.

Because mynamespace doesn't contain an init .py, setuptools.find_packages() won't find the sub-package. You must use setuptools.find_namespace_packages() instead or explicitly list all packages in your setup.py.

In addition: It's not that recommended to remove all __init__.py files in packages, check this detailed description from AndreasLukas : If you want to run a particular initialization script when the package or any of its modules or sub-packages are imported, you still require an init .py file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM