setuptools: ImportWarning when importing a PEP 420 namespace package
The pkg_resources
code is raising an ImportWarning
when it attempts to import a PEP 420 implicit namespace package:
ImportError: Failed to import test module: test.test_methods
Traceback (most recent call last):
File "/usr/lib/python3.5/unittest/loader.py", line 428, in _find_test_path
module = self._get_module_from_name(name)
File "/usr/lib/python3.5/unittest/loader.py", line 369, in _get_module_from_name
__import__(name)
File "/home/bignose/Projects/debian/dput/trunk/test/test_methods.py", line 26, in <module>
import testscenarios
File "/usr/lib/python3/dist-packages/testscenarios/__init__.py", line 57, in <module>
from testscenarios.scenarios import (
File "/usr/lib/python3/dist-packages/testscenarios/scenarios.py", line 34, in <module>
from testtools import iterate_tests
File "/usr/lib/python3/dist-packages/testtools/__init__.py", line 124, in <module>
from pbr.version import VersionInfo
File "/usr/lib/python3/dist-packages/pbr/version.py", line 25, in <module>
import pkg_resources
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3037, in <module>
@_call_aside
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3021, in _call_aside
f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3065, in _initialize_master_working_set
for dist in working_set
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3065, in <genexpr>
for dist in working_set
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2595, in activate
declare_namespace(pkg)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2163, in declare_namespace
_handle_ns(packageName, path_item)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2083, in _handle_ns
loader = importer.find_module(packageName)
File "<frozen importlib._bootstrap_external>", line 445, in _find_module_shim
ImportWarning: Not importing directory /usr/lib/python3/dist-packages/keyrings: missing __init__
(To reproduce this, enable the -W error
option to python3
. I did this to try to catch warnings in my code, assuming that libraries would not cause them š)
The āNot importing directory [ā¦] missing initā contradicts the explicit specification from PEP 420:
Namespace packages [as specified in this PEP] cannot contain an init.py .
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 19 (13 by maintainers)
Commits related to this issue
- Resolve warning filter issues There's an issue with 'pkgutils' and namespace packages. This has been reported against setuptools [1], but until this is resolved, we simply need to live with it. Ensur... — committed to stephenfin/sphinx by stephenfin 7 years ago
- Resolve warning filter issues There's an issue with 'pkgutils' and namespace packages. This has been reported against setuptools [1], but until this is resolved, we simply need to live with it. Ensur... — committed to stephenfin/sphinx by stephenfin 7 years ago
- Resolve warning filter issues There's an issue with 'pkgutils' and namespace packages. This has been reported against setuptools [1], but until this is resolved, we simply need to live with it. Ensur... — committed to stephenfin/sphinx by stephenfin 7 years ago
- Resolve warning filter issues There's an issue with 'pkgutils' and namespace packages. This has been reported against setuptools [1], but until this is resolved, we simply need to live with it. Ensur... — committed to stephenfin/sphinx by stephenfin 7 years ago
- Resolve warning filter issues There's an issue with 'pkgutils' and namespace packages. This has been reported against setuptools [1], but until this is resolved, we simply need to live with it. Ensur... — committed to stephenfin/sphinx by stephenfin 7 years ago
- Resolve warning filter issues There's an issue with 'pkgutils' and namespace packages. This has been reported against setuptools [1], but until this is resolved, we simply need to live with it. Ensur... — committed to stephenfin/sphinx by stephenfin 7 years ago
- Resolve warning filter issues There's an issue with 'pkgutils' and namespace packages. This has been reported against setuptools [1], but until this is resolved, we simply need to live with it. Ensur... — committed to stephenfin/sphinx by stephenfin 7 years ago
- Resolve warning filter issues There's an issue with 'pkgutils' and namespace packages. This has been reported against setuptools [1], but until this is resolved, we simply need to live with it. Ensur... — committed to stephenfin/sphinx by stephenfin 7 years ago
- Ignore ruamel import warnings The warnings are caused by pyfiglet importing pkg_resources. There's an issue about it here pypa/setuptools#1111. — committed to orlnub123/ASCII-ify by orlnub123 6 years ago
- Suppress warnings in importer.find_module. Fixes #1111. — committed to pypa/setuptools by jaraco 6 years ago
- Suppress warnings in importer.find_module. Fixes #1111. — committed to pypa/setuptools by jaraco 6 years ago
Iām seeing this as well. It is causing loads of noise in my logs when Python warnings are enabled. Here is a minimal bash script to demonstrate the error:
Actual output:
Glad I pasted my exact commands, because I started replicating it on my local workstation and couldnāt figure out what Iād done wrong. I see now I neglected to include the important
-W error
when I tried to replicate the issue above.Not sure if this will be of any help but the warning seems to occur on any namespace packages present in sys.modules that have a ānamespace_packages.txtā file in their metadata.