https://pantsbuild.org/ logo
w

wide-zoo-86070

04/26/2022, 5:30 PM
Hi team, a question on third party dependencies, let us say in the requirement.txt, there is
x.y==1.0
. In a python script, there is
from x.y import z
. It seems that Pants will complain
ModuleNotFoundError: No module named 'x'
. Is it expected? and how to solve it?
h

high-yak-85899

04/26/2022, 5:39 PM
Have you seen the module_mapping argument?
I've had to use this a few times
Pants comes with some built-in defaults, but it doesn't catch everything. Here's a taste of what we've had to do in our repo
Copy code
python_requirements(
    name="reqs",
    module_mapping={
        "pyzmq": ["zmq"],
        "ipython": ["IPython"],
        "pyserial": ["serial"],
        "pyserial-asyncio": ["serial_asyncio"],
        "python-can": ["can"]
    },
)
The
x.y==1.0
is confusing to me, though. Don't think I've ever seen dot notation in package names. Are you able to
pip install x.y
or only
pip install x
?
h

happy-kitchen-89482

04/26/2022, 5:50 PM
pants itself uses dot notation in the distribution package name! https://pypi.org/project/pantsbuild.pants/
😮 1
But the top-level import package is just
pants
What is the specific
x.y
in the example?
Because you need to be sure that you're using the right distribution name in requirements.txt and the right import name in
import
statements, and they may not be the same
👍 1
h

hundreds-father-404

04/26/2022, 6:05 PM
w

wide-zoo-86070

04/26/2022, 6:05 PM
Hi @happy-kitchen-89482 thanks for getting back. the x.y is equal to an internal lib we had
I look at that page. I am sure which section applies to my case : (
thanks guys. I found that the issue of not finding the module is due to another issue. I will post another thread.