Hi team, I’m having some issues with installing pa...
# general
j
Hi team, I’m having some issues with installing packages. I have my
requirements.txt
updated with
itsdangerous
and have ran
generate-lockfiles
and I can confirm see
itsdangerous
in the lock files. However, when I run the program, it keeps saying
ModuleNotFoundError: No module named 'itsdangerous'
1
Copy code
16:52:50.41 [INFO] Initializing scheduler...
16:52:50.62 [INFO] Scheduler initialized.
16:52:50.68 [WARN] No `.python-version` file found in the build root, but <PYENV_LOCAL> was set in `[python-bootstrap].search_path`.
16:52:50.95 [INFO] Preserving local process execution dir /private/var/folders/r6/16vxmbxs3t35l1cl_qfssmtr0000gn/T/pants-sandbox-zeedNb for Test binary /Users/yanqiang/.pyenv/shims/python3.
16:52:51.00 [INFO] Preserving local process execution dir /private/var/folders/r6/16vxmbxs3t35l1cl_qfssmtr0000gn/T/pants-sandbox-cCiFdk for Test binary /Users/yanqiang/.pyenv/shims/python.
16:52:52.13 [WARN] Pants cannot infer owners for the following imports in the target backend/xx-api:dev:

  * starlette.middleware.sessions.SessionMiddleware (line: 13)

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.14/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
16:52:52.15 [WARN] Pants cannot infer owners for the following imports in the target backend/xx-api/api/routes/xx.py:

  * starlette.status.HTTP_403_FORBIDDEN (line: 6)

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.14/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
16:52:52.15 [WARN] Pants cannot infer owners for the following imports in the target backend/xx-api/api/xx/xx.py:

  * motor.motor_asyncio.AsyncIOMotorClient (line: 7)

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.14/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
16:52:52.17 [WARN] Pants cannot infer owners for the following imports in the target backend/xx-xx/api/crud/xx.py:

  * elastic_transport.ObjectApiResponse (line: 5)

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.14/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
Traceback (most recent call last):
  File "/Users/yanqiang/.pyenv/versions/3.10.9/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/yanqiang/.pyenv/versions/3.10.9/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/yanqiang/.pex/unzipped_pexes/42acd679b974a41c721e349757d12085ff2ec915/__main__.py", line 103, in <module>
    bootstrap_pex(__entry_point__, execute=__execute__, venv_dir=__venv_dir__)
  File "/Users/yanqiang/.pex/unzipped_pexes/42acd679b974a41c721e349757d12085ff2ec915/.bootstrap/pex/pex_bootstrapper.py", line 601, in bootstrap_pex
    pex.PEX(entry_point).execute()
  File "/Users/yanqiang/.pex/unzipped_pexes/42acd679b974a41c721e349757d12085ff2ec915/.bootstrap/pex/pex.py", line 541, in execute
    sys.exit(self._wrap_coverage(self._wrap_profiling, self._execute))
  File "/Users/yanqiang/.pex/unzipped_pexes/42acd679b974a41c721e349757d12085ff2ec915/.bootstrap/pex/pex.py", line 448, in _wrap_coverage
    return runner(*args)
  File "/Users/yanqiang/.pex/unzipped_pexes/42acd679b974a41c721e349757d12085ff2ec915/.bootstrap/pex/pex.py", line 479, in _wrap_profiling
    return runner(*args)
  File "/Users/yanqiang/.pex/unzipped_pexes/42acd679b974a41c721e349757d12085ff2ec915/.bootstrap/pex/pex.py", line 568, in _execute
    return self.execute_entry(
  File "/Users/yanqiang/.pex/unzipped_pexes/42acd679b974a41c721e349757d12085ff2ec915/.bootstrap/pex/pex.py", line 752, in execute_entry
    return self.execute_module(entry_point.module)
  File "/Users/yanqiang/.pex/unzipped_pexes/42acd679b974a41c721e349757d12085ff2ec915/.bootstrap/pex/pex.py", line 760, in execute_module
    runpy.run_module(module_name, run_name="__main__", alter_sys=True)
  File "/Users/yanqiang/.pyenv/versions/3.10.9/lib/python3.10/runpy.py", line 224, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/Users/yanqiang/.pyenv/versions/3.10.9/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Users/yanqiang/.pyenv/versions/3.10.9/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/yanqiang/.pex/unzipped_pexes/42acd679b974a41c721e349757d12085ff2ec915/api/main.py", line 13, in <module>
    from starlette.middleware.sessions import SessionMiddleware
  File "/Users/yanqiang/.pex/installed_wheels/39a06063c062020fcce171a1c8a825da6edba1b155290b26f540ae12099413b3/starlette-0.26.1-py3-none-any.whl/starlette/middleware/sessions.py", line 6, in <module>
    import itsdangerous
ModuleNotFoundError: No module named 'itsdangerous'
16:52:54.14 [INFO] Preserving local process execution dir /private/var/folders/r6/16vxmbxs3t35l1cl_qfssmtr0000gn/T/pants-sandbox-aQQn4i for interactive process
e
Looks like you need to depend on
starlette[full]
instead of just
starlette
: https://github.com/encode/starlette/blob/8965f8849977b5752e415722a83aa00049f80ff3/pyproject.toml#L35-L37 Do you?
That's noted here fwiw as well: https://github.com/encode/starlette#dependencies
b
Alternatively, if you only want
itsdangerous
and not all the other optional deps, you can use
overrides
in your
python_requirements
to tell pants that any time it sees
starlette
it should also infer a dependency on
itsdangerous
, along the lines of https://www.pantsbuild.org/docs/python-third-party-dependencies#requirements-with-undeclared-dependencies
j
ah, yeah, I use fastapi, so
fastapi[all]
works now. I do only want to install necessary packages though, will take a look at overrides. A related question, I think pants is doing dependencies inference, so if I installed all optional deps, but only use some of them, will pants package subset of all the deps?
h
Yes, pants uses only the necessary subset of a resolve. Of course, that subset may be too small if there is a necessary dep that couldn't be inferred, in which case you can add a manual dep in the relevant BUILD file.
👍 1