https://pantsbuild.org/ logo
#general
Title
# general
a

average-father-89924

04/18/2023, 9:24 AM
Hi, I am getting a
ModuleNotFoundError: No module named 'azure.cosmos'
. I added the package, generated the locks and exported (azure-cosmos exists in pyproject.toml, the lock files, and also in the dist/.../python/../bin. So, I am pretty sure it is there. I searched here on slack and read the documentation that I need to do a
python_requirement(name="azure-cosmos", requirements=["azure-cosmos"])
in my BUILD file, which I did but to no avail. The
azure-cosmos
package is used by a submodul that I am importing. I added the
python_requirement
line to both BUILD files in the submodule as well as in my main module. I add the stack trace in the thread. Any help is appreciated!
1
112409.33 [WARN] Pants cannot infer owners for the following imports in the target src/libraries/helpers/cosmosdb/cosmosdb_client.py:
* azure.cosmos.ContainerProxy (line: 7)
* azure.cosmos.cosmos_client (line: 7)
* azure.cosmos.exceptions.CosmosResourceNotFoundError (line: 8)
* azure.cosmos.partition_key.PartitionKey (line: 9)
* jsonpath_rw.parse (line: 10)
If you do not expect an import to be inferrable, add
# pants: no-infer-dep
to the import line. Otherwise, see https://www.pantsbuild.org/v2.15/docs/troubleshooting#import-errors-and-missing-dependencies for common problems.
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/sebastian/.pex/unzipped_pexes/91c255f54921186402d85f04ad29d5924705f8ab/__main__.py", line 103, in <module>
bootstrap_pex(__entry_point__, execute=execute, venv_dir=__venv_dir__)
File "/home/sebastian/.pex/unzipped_pexes/91c255f54921186402d85f04ad29d5924705f8ab/.bootstrap/pex/pex_bootstrapper.py", line 599, in bootstrap_pex
pex.PEX(entry_point).execute()
File "/home/sebastian/.pex/unzipped_pexes/91c255f54921186402d85f04ad29d5924705f8ab/.bootstrap/pex/pex.py", line 551, in execute
sys.exit(self._wrap_coverage(self._wrap_profiling, self._execute))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/sebastian/.pex/unzipped_pexes/91c255f54921186402d85f04ad29d5924705f8ab/.bootstrap/pex/pex.py", line 458, in _wrap_coverage
return runner(*args)
^^^^^^^^^^^^^
File "/home/sebastian/.pex/unzipped_pexes/91c255f54921186402d85f04ad29d5924705f8ab/.bootstrap/pex/pex.py", line 489, in _wrap_profiling
return runner(*args)
^^^^^^^^^^^^^
File "/home/sebastian/.pex/unzipped_pexes/91c255f54921186402d85f04ad29d5924705f8ab/.bootstrap/pex/pex.py", line 594, in _execute
return self.execute_entry(
^^^^^^^^^^^^^^^^^^^
File "/home/sebastian/.pex/unzipped_pexes/91c255f54921186402d85f04ad29d5924705f8ab/.bootstrap/pex/pex.py", line 775, in execute_entry
return self.execute_module(entry_point.module)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/sebastian/.pex/unzipped_pexes/91c255f54921186402d85f04ad29d5924705f8ab/.bootstrap/pex/pex.py", line 783, in execute_module
runpy.run_module(module_name, run_name="__main__", alter_sys=True)
File "<frozen runpy>", line 222, in run_module
File "<frozen runpy>", line 112, in _get_module_details
File "/home/sebastian/.pex/unzipped_pexes/91c255f54921186402d85f04ad29d5924705f8ab/functions/cosmos_db/__init__.py", line 1, in <module>
from libraries.helpers.cosmosdb.cosmosdb_client import CosmosDBClient, CosmosDBConfig
File "/home/sebastian/.pex/unzipped_pexes/91c255f54921186402d85f04ad29d5924705f8ab/libraries/helpers/cosmosdb/cosmosdb_client.py", line 7, in <module>
from azure.cosmos import ContainerProxy, cosmos_client
ModuleNotFoundError: No module named 'azure.cosmos'
w

worried-painter-31382

04/18/2023, 9:50 AM
The error you're seeing is that pants will not guess that
azure-cosmos
provides
azure.cosmos
when inferring dependencies. This is not uncommon, so pants provides an extensive default mapping, but I don't think azure-cosmos is in there.
https://www.pantsbuild.org/docs/reference-python_requirement#codemodulescode is also (more) relevant, since your target is a single
python_requirement
.
a

average-father-89924

04/18/2023, 11:20 AM
Thanks a lot, Tobias! That solved it!
h

happy-kitchen-89482

04/18/2023, 2:33 PM
Looks like azure-cosmos was added to the default mappings in https://github.com/pantsbuild/pants/pull/18016
Which will make it into 2.16
So once you're on 2.16 you can remove your custom mapping