-
-
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
python3.6 can't import installed namespace package if another package in the same namespace is put locally and pkg_resources are imported #1321
Comments
daa
changed the title
python3.6 can't import installed namespace package if another package in the sampe namespace is put locally and pkg_resources are imported
python3.6 can't import installed namespace package if another package in the same namespace is put locally and pkg_resources are imported
Apr 10, 2018
2 tasks
I've found that this is issue is similar to #900 and proposed pull-request should fix that issue too. |
jaraco
added a commit
that referenced
this issue
Sep 16, 2018
…ce-package-path Improved handling of module __path__ attribute for namespace packages, fixes #1321
theacodes
pushed a commit
to googleapis/google-auth-library-python
that referenced
this issue
Feb 27, 2019
I was using `pex` on an application that lists `google-auth` as a dependency and got the following warning: ..../pex/environment.py:330 UserWarning: The `pkg_resources` package was loaded from a pex vendored version when declaring namespace packages defined by google-auth 1.6.2. The google-auth 1.6.2 distribution should fix its `install_requires` to include `setuptools` So adding `setuptools` as a listed dependency to fix this. Version `40.3.0` was chosen because it fixed a bug in the handling of `pkg_resource`-style namespaces (pypa/setuptools#1321). For more details on why this version was picked, see the discussion in #322. Also making the listing alphabetical.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Recently I've met an issue with python3.6 and
pkg_resources
-style namespace packages when for one namespace one package is installed into virtualenv (a) and one is located in current directory (b) - after importingpkg_resources
orsetuptools
package a becomes inaccessible. But no such behaviour is observed with python2.7. To be more clear I have an example:As you can see
pkgns.pkga
installed in virtualenv was successfully imported under python2.7 and failed under python3.6. For me this is an issue because our code is structured similarly and some our packages contain helper functions to use insetup.py
but this bug prevents me from using them. I had a workaround by using older setuptools to build helper packages but this is not a very reliable solution.I investigated an issue further:
So
pkg_resources
during import changed namespace package__path__
attribute in one case correctly and in second not - old path was lost. Also one may notice that under python3.6 original path is not list but_NamespacePath
object and this gives us a key to understanding source of problem. Let's look atnspkg.pth
file:If python version is greater than 3.5
pkgns
module entry is created usingimportlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec(...))
function which gives real pep420 namespace package,pkg_resources
on import adjusts namespace packages paths but handles only lists as original path in_rebuild_mod_path()
inhandle_ns()
function (commit 7c0c39e to fix #885):So what happens briefly:
pkg_resources
tries to fix namespace packages paths on import, and inside_handle_ns()
loads module (pkgns.pkgb
in my example), after thispkgns
'__path__
attribute points to package in current directory,orig_path
points to old_NamespacePath
object and_rebuild_mod_path
does not handle this combination leaving new path not fixed.Here are versions of software I used: setuptools-39.0.1, pip-9.0.3, python-2.7.14, python-3.6.4 and python-3.6.5.
I can see at least 2 ways to fix the issue - assign
module.__path__
toorig_path
when the latter is not a list or to convert it to list and proceed with sorting and normalizing, but I cannot currently predict consequences of both decisions.The text was updated successfully, but these errors were encountered: