I hit an issue today with a `ModuleNotFoundError` ...
# general
n
I hit an issue today with a
ModuleNotFoundError
for
flask_compress
while using Dash.
Copy code
ImportError: To use the compress option, you need to install dash[compress]
I added an override for the 3rd party optional dependency
Copy code
python_requirements(
  name="reqs",
  overrides={
    "dash": {
      "dependencies": [":reqs#Flask-Compress"],      
    }
  }
)
but it still wasn't working. Turns out I had both
flask-compress=1.13
and
Flask-Compress
in requirements.txt. After removing the latter, it works. It works with just one or the other, or both with versions specified, but not in this first scenario. I'm not sure why. I'm mainly posting for anyone else that searches for this specifically in future, but curious if Pants can do anything to better help here or if it's a bug.
🫶 2
c
TIL pip is case-insensitive. I think the error might have to do with ambiguous dependency ownership. When I try adding both
flask-compress==1.13
and
Flask-Compress
to a requirements.txt, and
import flask_compress
, I get the ambiguity warning below, and then Pants fails because it can't determine an owner.
Copy code
[WARN] The target testprojects/src/python/sources/sources.py imports `flask_compress`, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: ['testprojects/src/python:reqs#Flask-Compress', 'testprojects/src/python:reqs#flask-compress'].
If instead the import exists in a "weak" form (for example, inside of a try-except ImportError like would happen with a package's extra) then Pants will not mandate that a unique owner can be found (because you might not be using that extra). Unfortunately, the warning can be cached and not re-emitted, which is be frustrating. There's the source-analysis extra, which is a lot but really details the inner thoughts of Pants https://www.pantsbuild.org/docs/reference-python-dump-source-analysis . Although it looks like the weak-ignore took precedence over the ambiguous resolution
👍 1
n
I did notice that cached warnings disappear which is a bit annoying, but I was also invalidating the cache when requirements change, and not seeing anything. Hmm. When I run with
pants --no-local-cache test
I don't get the import error. When I run with cache I do. I don't see flask-compress in the source analysis dump in any case.
c
oh, right, of course. Pants won't analyse the source of the dependencies, it uses the requirements for them. not sure why --no-local-cache would not give the error, though...