-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImportWarning when importing a PEP 420 namespace package #1111
Comments
I am not very familiar with namespace packages, so I could be wrong about where the fault lies. I am sure, though, that there is a fault, and it needs to be resolved to avoid the |
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: #!/bin/bash
rm -rf venv
python3 -m venv venv
venv/bin/pip install sphinxcontrib-websupport
venv/bin/python -Werror -c 'import pkg_resources' Actual output:
|
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. Ensure said warnings are filtered from tox too and remove an unnecessary one. [1] pypa/setuptools#1111 Signed-off-by: Stephen Finucane <[email protected]>
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. Ensure said warnings are filtered from tox too and remove an unnecessary one. [1] pypa/setuptools#1111 Signed-off-by: Stephen Finucane <[email protected]>
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. Ensure said warnings are filtered from tox too and remove an unnecessary one. [1] pypa/setuptools#1111 Signed-off-by: Stephen Finucane <[email protected]>
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. Ensure said warnings are filtered from tox too and remove some unnecessary ones. [1] pypa/setuptools#1111 Signed-off-by: Stephen Finucane <[email protected]>
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. Ensure said warnings are filtered from tox too and remove some unnecessary ones. [1] pypa/setuptools#1111 Signed-off-by: Stephen Finucane <[email protected]>
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. Ensure said warnings are filtered from tox too and remove some unnecessary ones. [1] pypa/setuptools#1111 Signed-off-by: Stephen Finucane <[email protected]>
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. Ensure said warnings are filtered from tox too and remove some unnecessary ones. [1] pypa/setuptools#1111 Signed-off-by: Stephen Finucane <[email protected]>
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. Ensure said warnings are filtered from tox too and remove some unnecessary ones. [1] pypa/setuptools#1111 Signed-off-by: Stephen Finucane <[email protected]>
The warnings are caused by pyfiglet importing pkg_resources. There's an issue about it here pypa/setuptools#1111.
As noted above, the lack of init.py is fine according to PEP420. The error itself comes from the builtin imp module in python2.7:
So the real fix for this is for python itself to stop complaining (given it just works), or barring that suppress the warning in the package that calls it, which is setuptools. |
One plan that addresses this issue is to replace the vast majority of uses of pkg_resources with stdlib functionality (and backports), such as with importlib_resources, importlib_metadata and entrypoints.
I tried replicating the minimal script on Python 3.7, but it fails first on another warning:
I've reported that in #1480. I tried replicating the issue on Python 3.6 but couldn't:
I should note that if you have rwt (and you should), it's easier and cleaner to test with this one liner (and doesn't leave you with ./venv):
Let's see if we can ascertain why the issue exists in your environment but not in mine. |
I upgraded my setuptools and pip and still no issue:
|
I tested on Python 3.5.2 and 3.6.4 and 3.6.6, but none of those exhibit the reported failure. Maybe the issue has gone away? |
The issue still occurs for me, with Python 3.6.6. Using a slightly enhanced version of @jdufresne's test script: #! /bin/bash
VENV_DIR="$(realpath ./venv)"
rm -rf "$VENV_DIR"
python3 -m venv "$VENV_DIR"
"$VENV_DIR"/bin/python3 --version
"$VENV_DIR"/bin/python3 -m pip install sphinxcontrib-websupport
"$VENV_DIR"/bin/python3 -W error -c 'import pkg_resources' The output I get:
|
@bignose-debian Would you consider creating a Dockerfile that replicates the issue? With that, I could troubleshoot in the environment where the issue occurs. |
@jaraco wrote:
Yes, though I haven't a clue how to do that (nor how to know whether the result would correctly replicate the behaviour). |
I'll take a stab at it. |
I was able to replicate thus:
|
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. |
So I've confirmed the .pth file is present and that causes |
Modules that have |
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 |
I learned that removing the
|
Digging deeper, I see why the absence of the |
Removing setuptools from the equation, I can replicate the failure with this Dockerfile:
emits
|
I'm glad you got such good diagnosis. The Dockerfile doesn't help me much because I just get a bunch of permission errors trying to use it. (I don't have Docker set up on any of my machines so I'm probably not best suited for going down that path for diagnosis.) |
The
pkg_resources
code is raising anImportWarning
when it attempts to import a PEP 420 implicit namespace package:(To reproduce this, enable the
-W error
option topython3
. 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:
The text was updated successfully, but these errors were encountered: