question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'[IndexError] list index out of range' on poetry install in Docker if packages is specified

See original GitHub issue
  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Issue

A common technique when creating a Dockerfile is to copy pyproject.toml and poetry.lock, then running poetry install.

Like so:

COPY pyproject.toml poetry.lock ./
RUN poetry install --no-dev 
# then, add the rest of the project to only run
# poetry install when pyproject.toml/poetry.lock changes
COPY . /app

However, if the project is contains packages (see example pyproject.toml linked above), poetry will fail to find these, as they hasn’t been copied over yet, and throw error:

[IndexError]
list index out of range

Traceback (most recent call last):
  File "/root/.poetry/lib/poetry/_vendor/py3.7/clikit/console_application.py", line 131, in run
    status_code = command.handle(parsed_args, io)
  File "/root/.poetry/lib/poetry/_vendor/py3.7/clikit/api/command/command.py", line 120, in handle
    status_code = self._do_handle(args, io)
  File "/root/.poetry/lib/poetry/_vendor/py3.7/clikit/api/command/command.py", line 171, in _do_handle
    return getattr(handler, handler_method)(args, io, self)
  File "/root/.poetry/lib/poetry/_vendor/py3.7/cleo/commands/command.py", line 92, in wrap_handle
    return self.handle()
  File "/root/.poetry/lib/poetry/console/commands/install.py", line 72, in handle
    builder = EditableBuilder(self.poetry, self._env, NullIO())
  File "/root/.poetry/lib/poetry/masonry/builders/builder.py", line 68, in __init__
    includes=self._package.include,
  File "/root/.poetry/lib/poetry/masonry/utils/module.py", line 72, in __init__
    source=package.get('from'),
  File "/root/.poetry/lib/poetry/masonry/utils/package_include.py", line 15, in __init__
    self.check_elements()
  File "/root/.poetry/lib/poetry/masonry/utils/package_include.py", line 37, in check_elements
    root = self._elements[0]

One can get around this by installing with --no-root flag:

RUN poetry install --no-dev --no-root

Related: #1247

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:13
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mcouthoncommented, Apr 2, 2020

My current workaround for this is as follows:

# Only copying these files here in order to take advantage of Docker cache. We only want the
# next stage (poetry install) to run if these files change, but not the rest of the app.
COPY pyproject.toml poetry.lock ./

# Currently poetry install is significantly slower than pip install, so we're creating a
# requirements.txt output and running pip install with it.
# Follow this issue: https://github.com/python-poetry/poetry/issues/338
# Setting --without-hashes because of this issue: https://github.com/pypa/pip/issues/4995
RUN poetry config virtualenvs.create false \
                && poetry export --without-hashes -f requirements.txt --dev \
                |  poetry run pip install -r /dev/stdin \
                && poetry debug

COPY  . ./

# Because initially we only copy the lock and pyproject file, we can only install the dependencies
# in the RUN above, as the `packages` portion of the pyproject.toml file is not
# available at this point. Now, after the whole package has been copied in, we run `poetry install`
# again to only install packages, scripts, etc. (and thus it should be very quick).
# See this issue for more context: https://github.com/python-poetry/poetry/issues/1899
RUN poetry install --no-interaction

# We're setting the entrypoint to `poetry run` because poetry installed entry points aren't
# available in the PATH by default, but it is available for `poetry run`
ENTRYPOINT ["poetry", "run"]

Hope this helps someone.

0reactions
neersightedcommented, Oct 5, 2022

Duplicate #1301.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Poetry Index Error – list index out of range
So far I've identified two things that you need to check. Credentials: If you are installing packages from a private repository, ...
Read more >
Running Poetry install command gives error : list index out of ...
I am not sure if there is a simpler method for this: install pyenv https://github.com/pyenv/pyenv-installer. with pyenv run command.
Read more >
Managing dependencies | Documentation - Poetry
Managing dependencies Dependency groups Poetry provides a way to organize your dependencies by groups. For instance, you might have dependencies that are ...
Read more >
Bug #50691: cephadm: bootstrap fails with "IndexError: list ...
cephadm: bootstrap fails with "IndexError: list index out of range" during ... Running on a cleanly installed Debian 10.9 host with ceph/cephadm 16.2.3....
Read more >
Python in VSCode: Running and Debugging
If you define project-specific settings in VSCode, the IDE creates a new file, .vscode/settings.json ... IndexError: list index out of range.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found