Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running poetry install fails sometimes with new-installer #3336

Closed
3 tasks done
austinbutler opened this issue Nov 7, 2020 · 17 comments
Closed
3 tasks done

Running poetry install fails sometimes with new-installer #3336

austinbutler opened this issue Nov 7, 2020 · 17 comments
Labels
kind/bug Something isn't working as expected
Milestone

Comments

@austinbutler
Copy link

austinbutler commented Nov 7, 2020

Issue

At random, poetry install will fail with the following error. The package being installed by pip changes, but the brotli error doesn't change.

  EnvCommandError

  Command ['/home/runner/work/poetry-test/poetry-test/.venv/bin/pip', 'install', '--no-deps', '/home/runner/.cache/pypoetry/artifacts/6c/0f/ea/fb7dbaaaac5e39918d0139753cfaeab4348e2b4f652e4c43e63e41db21/cchardet-2.1.7-cp38-cp38-manylinux2010_x86_64.whl'] errored with the following return code 1, and output: 
  Traceback (most recent call last):
    File "/home/runner/work/poetry-test/poetry-test/.venv/bin/pip", line 8, in <module>
      sys.exit(main())
    File "/home/runner/work/poetry-test/poetry-test/.venv/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 73, in main
      command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
    File "/home/runner/work/poetry-test/poetry-test/.venv/lib/python3.8/site-packages/pip/_internal/commands/__init__.py", line 104, in create_command
      module = importlib.import_module(module_path)
    File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/importlib/__init__.py", line 127, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
    File "<frozen importlib._bootstrap>", line 991, in _find_and_load
    File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 783, in exec_module
    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    File "/home/runner/work/poetry-test/poetry-test/.venv/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 17, in <module>
      from pip._internal.cli.req_command import RequirementCommand, with_cleanup
    File "/home/runner/work/poetry-test/poetry-test/.venv/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 16, in <module>
      from pip._internal.index.collector import LinkCollector
    File "/home/runner/work/poetry-test/poetry-test/.venv/lib/python3.8/site-packages/pip/_internal/index/collector.py", line 14, in <module>
      from pip._vendor import html5lib, requests
    File "/home/runner/work/poetry-test/poetry-test/.venv/lib/python3.8/site-packages/pip/_vendor/requests/__init__.py", line 43, in <module>
      from pip._vendor import urllib3
    File "/home/runner/work/poetry-test/poetry-test/.venv/lib/python3.8/site-packages/pip/_vendor/urllib3/__init__.py", line 7, in <module>
      from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
    File "/home/runner/work/poetry-test/poetry-test/.venv/lib/python3.8/site-packages/pip/_vendor/urllib3/connectionpool.py", line 39, in <module>
      from .response import HTTPResponse
    File "/home/runner/work/poetry-test/poetry-test/.venv/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 156, in <module>
      class HTTPResponse(io.IOBase):
    File "/home/runner/work/poetry-test/poetry-test/.venv/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 389, in HTTPResponse
      DECODER_ERROR_CLASSES += (brotli.error,)
  AttributeError: module 'brotli' has no attribute 'error'
  

  at ~/.poetry/lib/poetry/utils/env.py:1074 in _run
      1070│                 output = subprocess.check_output(
      1071│                     cmd, stderr=subprocess.STDOUT, **kwargs
      1072│                 )
      1073│         except CalledProcessError as e:
    → 1074│             raise EnvCommandError(e, input=input_)
      1075│ 
      1076│         return decode(output)
      1077│ 
      1078│     def execute(self, bin, *args, **kwargs):

So far it doesn't seem to happen from a normal interactive shell on macOS, but that could just be random luck. However CI at work in Jenkins has been flaky and even local builds in Docker show the same issue.

What seems to fix it is setting new-installer = false.

I realize there are already a few issues opened that are possibly similar (related to race conditions and parallel installs), but I was able to replicate it in an example GitHub action so figured maybe that could help.

@austinbutler austinbutler added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Nov 7, 2020
@sinoroc
Copy link

sinoroc commented Nov 7, 2020

The error message contains /home/runner/.cache/pypoetry/artifacts/6c/0f/ea/fb7dbaaaac5e39918d0139753cfaeab4348e2b4f652e4c43e63e41db21/cchardet-2.1.7-cp38-cp38-manylinux2010_x86_64.whl. I would suspect there was an issue during the download of that file or while writing that file on disk.

If this file is still on your local file system, would you mind trying to inspect it manually? For example verify the checksum, or since it should be just a simple zip file in disguise, try to open this archive with your usual favorite unzip program. Or maybe something like:

python3 -m zipfile -l /home/runner/.cache/pypoetry/artifacts/6c/0f/ea/fb7dbaaaac5e39918d0139753cfaeab4348e2b4f652e4c43e63e41db21/cchardet-2.1.7-cp38-cp38-manylinux2010_x86_64.whl

@austinbutler
Copy link
Author

Added a step to the CI to upload the artifacts on failure and that worked for getting a copy on another failed run.

Failure this time was on CairoSVG-2.4.2-py3-none-any.whl.

The sha256 from PyPi is 9cb1df7e9bc60f75fb87f67940a8fb805aad544337a67a40b67c05cfe33711a2.

The sha256 of the file from the artifacts on that build matches PyPi:

❯ sha256sum CairoSVG-2.4.2-py3-none-any.whl 
9cb1df7e9bc60f75fb87f67940a8fb805aad544337a67a40b67c05cfe33711a2  CairoSVG-2.4.2-py3-none-any.whl

@sinoroc
Copy link

sinoroc commented Nov 8, 2020

I see. I do not know how to go on on from there then. My first impression is that it could have been a similar issue as this one (probably a download went wrong), but your issue seems to be different.

@austinbutler
Copy link
Author

To test that it works consistently with the parallel installer disabled, I disabled it in poetry.toml, then ran five more builds in a row and they all worked.

@kleschenko
Copy link

We are also getting a lot of flakiness using the new installer in our CI builds. For example, those are errors from the three consecutive retries of the same build:

  Command ['/usr/local/bin/python', '-m', 'pip', 'install', '--no-deps', '-U', '/root/.cache/pypoetry/artifacts/49/8a/46/de22c63977d20779dfe015492e797c0a4a785b6eea29f775267d233805/python-Levenshtein-0.12.0.tar.gz'] errored with the following return code 1, and output: 
  Processing /root/.cache/pypoetry/artifacts/49/8a/46/de22c63977d20779dfe015492e797c0a4a785b6eea29f775267d233805/python-Levenshtein-0.12.0.tar.gz
      ERROR: Command errored out with exit status 1:
       command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-_izpglc5/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-_izpglc5/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-33zyawy4
           cwd: /tmp/pip-req-build-_izpglc5/
      Complete output (19 lines):
      running egg_info
      creating /tmp/pip-pip-egg-info-33zyawy4/python_Levenshtein.egg-info
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/tmp/pip-req-build-_izpglc5/setup.py", line 46, in <module>
          """,
        File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 161, in setup
          return distutils.core.setup(**attrs)
        File "/usr/local/lib/python3.7/distutils/core.py", line 148, in setup
          dist.run_commands()
        File "/usr/local/lib/python3.7/distutils/dist.py", line 966, in run_commands
          self.run_command(cmd)
        File "/usr/local/lib/python3.7/distutils/dist.py", line 985, in run_command
          cmd_obj.run()
        File "/usr/local/lib/python3.7/site-packages/setuptools/command/egg_info.py", line 289, in run
          writer = ep.resolve()
        File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2468, in resolve
          module = __import__(self.module_name, fromlist=['__name__'], level=0)
      ModuleNotFoundError: No module named 'pbr'
      ----------------------------------------
  ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  WARNING: You are using pip version 20.1.1; however, version 20.2.4 is available.
  You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
  

  at /pyroot/lib/python3.7/site-packages/poetry/utils/env.py:1074 in _run
      1070│                 output = subprocess.check_output(
      1071│                     cmd, stderr=subprocess.STDOUT, **kwargs
      1072│                 )
      1073│         except CalledProcessError as e:
    → 1074│             raise EnvCommandError(e, input=input_)
      1075│ 
      1076│         return decode(output)
      1077│ 
      1078│     def execute(self, bin, *args, **kwargs):
  Command ['/usr/local/bin/python', '-m', 'pip', 'install', '--no-deps', '-U', '/root/.cache/pypoetry/artifacts/49/8a/46/de22c63977d20779dfe015492e797c0a4a785b6eea29f775267d233805/python-Levenshtein-0.12.0.tar.gz'] errored with the following return code 1, and output: 
  Processing /root/.cache/pypoetry/artifacts/49/8a/46/de22c63977d20779dfe015492e797c0a4a785b6eea29f775267d233805/python-Levenshtein-0.12.0.tar.gz
      ERROR: Command errored out with exit status 1:
       command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-d2hj8zxh/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-d2hj8zxh/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-buna0r_h
           cwd: /tmp/pip-req-build-d2hj8zxh/
      Complete output (3 lines):
      running egg_info
      creating /tmp/pip-pip-egg-info-buna0r_h/python_Levenshtein.egg-info
      error: [Errno 2] No such file or directory: '/pyroot/lib/python3.7/site-packages/~br-5.5.1.dist-info/METADATA'
      ----------------------------------------
  ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  WARNING: You are using pip version 20.1.1; however, version 20.2.4 is available.
  You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
  

  at /pyroot/lib/python3.7/site-packages/poetry/utils/env.py:1074 in _run
      1070│                 output = subprocess.check_output(
      1071│                     cmd, stderr=subprocess.STDOUT, **kwargs
      1072│                 )
      1073│         except CalledProcessError as e:
    → 1074│             raise EnvCommandError(e, input=input_)
      1075│ 
      1076│         return decode(output)
      1077│ 
      1078│     def execute(self, bin, *args, **kwargs):
  Command ['/usr/local/bin/python', '-m', 'pip', 'install', '--no-deps', '-U', '/root/.cache/pypoetry/artifacts/e5/29/47/442c47c9e875153abd2315ffc8b40e50a84dc8ac5011d9bf1530673205/uvicorn-0.12.2-py3-none-any.whl'] errored with the following return code 2, and output: 
  ERROR: Exception:
  Traceback (most recent call last):
    File "/usr/local/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 188, in _main
      status = self.run(options, args)
    File "/usr/local/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 185, in wrapper
      return func(self, options, args)
    File "/usr/local/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 278, in run
      session = self.get_default_session(options)
    File "/usr/local/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 83, in get_default_session
      self._session = self.enter_context(self._build_session(options))
    File "/usr/local/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 100, in _build_session
      index_urls=self._get_index_urls(options),
    File "/usr/local/lib/python3.7/site-packages/pip/_internal/network/session.py", line 249, in __init__
      self.headers["User-Agent"] = user_agent()
    File "/usr/local/lib/python3.7/site-packages/pip/_internal/network/session.py", line 159, in user_agent
      setuptools_version = get_installed_version("setuptools")
    File "/usr/local/lib/python3.7/site-packages/pip/_internal/utils/misc.py", line 634, in get_installed_version
      working_set = pkg_resources.WorkingSet()
    File "/usr/local/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 567, in __init__
      self.add_entry(entry)
    File "/usr/local/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 623, in add_entry
      for dist in find_distributions(entry, True):
    File "/usr/local/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2065, in find_on_path
      for dist in factory(fullpath):
    File "/usr/local/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2127, in distributions_from_metadata
      if len(os.listdir(path)) == 0:
  FileNotFoundError: [Errno 2] No such file or directory: '/pyroot/lib/python3.7/site-packages/~lackclient-2.9.3.dist-info'
  WARNING: You are using pip version 20.1.1; however, version 20.2.4 is available.
  You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
  

  at /pyroot/lib/python3.7/site-packages/poetry/utils/env.py:1074 in _run
      1070│                 output = subprocess.check_output(
      1071│                     cmd, stderr=subprocess.STDOUT, **kwargs
      1072│                 )
      1073│         except CalledProcessError as e:
    → 1074│             raise EnvCommandError(e, input=input_)
      1075│ 
      1076│         return decode(output)
      1077│ 
      1078│     def execute(self, bin, *args, **kwargs):

@max-wittig
Copy link

I encounter the same issue, when running in CI. It's sporadic and seems to be related to the new installer.

@dlouzan
Copy link

dlouzan commented May 4, 2021

We've encountered this also running our builds on gitlab-ci, randomly builds will fail, not only running directly on the runner docker executor, also inside kaniko builds. The only solution has been to disable the new installer as documented above:

poetry config experimental.new-installer false

@sdispater sdispater added this to the 1.2 milestone May 4, 2021
Shivansh-007 added a commit to discord-modmail/modmail that referenced this issue Aug 12, 2021
------------
The Problems
------------
There are namely two problems which are being fixed in this issue:

1. `pyproject.toml` defines `modmail` package to be included, thus
poetry searches for it but finds it be to be empty as originally
we copied the poetry meta files only before installing and then
copied rest of the package.

2. We are using pip to install poetry, we uses the new installer,
the new installer has a known bug see python-poetry/poetry#3336 but
the issue hasn't shown any acitivty since it has been opened
unfortunately.

------------
The Solution
-----------

1. I have moved `COPY . .` to be ran before poetry install so
poetry can find what the package to be included.

2. The only possible solution to this is to disable the old
installer which was causing this bug for some reason.
Shivansh-007 added a commit to discord-modmail/modmail that referenced this issue Aug 14, 2021
------------
The Problems
------------
There are namely two problems which are being fixed in this issue:

1. `pyproject.toml` defines `modmail` package to be included, thus
poetry searches for it but finds it be to be empty as originally
we copied the poetry meta files only before installing and then
copied rest of the package.

2. We are using pip to install poetry, we uses the new installer,
the new installer has a known bug see python-poetry/poetry#3336 but
the issue hasn't shown any acitivty since it has been opened
unfortunately.

------------
The Solution
-----------

1. I have moved `COPY . .` to be ran before poetry install so
poetry can find what the package to be included.

2. The only possible solution to this is to disable the old
installer which was causing this bug for some reason.
@nhopp
Copy link

nhopp commented Aug 17, 2021

I am seeing this issue using Poetry 1.1.7 in docker with the proposed workaround

RUN poetry env use system
RUN poetry config experimental.new-installer false
RUN poetry config virtualenvs.create false && poetry install

error installing

  Command ['/opt/hostedtoolcache/Python/3.9.6/x64/bin/python', '-m', 'pip', 'install', '--no-deps', '/home/runner/.cache/pypoetry/artifacts/b5/48/a1/d2b823337003d531d87cf0d503ef28bb579703a74d14ad24a88863d616/pickleshare-0.7.5-py2.py3-none-any.whl'] errored with the following return code 1, and output: 
  Processing /home/runner/.cache/pypoetry/artifacts/b5/48/a1/d2b823337003d531d87cf0d503ef28bb579703a74d14ad24a88863d616/pickleshare-0.7.5-py2.py3-none-any.whl
  ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/opt/hostedtoolcache/Python/3.9.6/x64/lib/python3.9/site-packages/packaging-20.9.dist-info'
  

@lietu
Copy link

lietu commented Sep 8, 2021

I've also implemented the workaround in my base images and my issues with AttributeError: module 'brotli' has no attribute 'error' are gone.

https://github.com/lietu/docker-images/blob/98c1d3938e6f3d760e005f3c0e4cca0be9824d2e/python-base/ubuntu20.04-python3.9/docker/scripts/configure_poetry.sh#L8

@brnosouza
Copy link

is this still valid?

@max-wittig
Copy link

Yes, no new version was released to address this problem. In some repos: poetry config experimental.new-installer false is still required.

@benjaminsweetnam247
Copy link

can we make the experimental not the default this has been driving me nuts for days thanks

@abn
Copy link
Member

abn commented Mar 23, 2022

See #3010 (comment) for a bit more context on the FileNotFoundError. TL;DR this is a side-effect of running multiple pip instances (parallel install).

Poetry 1.2 should fare better as the newer pip releases are less prone to this and poetry will now use an embedded pip version instead of system one (which in the above case is likely older) and install will not by default remove unused system packages.

Also, you might have better results if you stop doing poetry config virtualenvs.create false.

honzajavorek added a commit to juniorguru/junior.guru that referenced this issue Apr 25, 2022
@abn
Copy link
Member

abn commented May 10, 2022

Can someone confirm that this is resolved with Poetry from poetry@master (or latest pre-release).

Alternatively, in environments where this is a risk, you cna also consider the mitigation.

poetry config installer.max-workers=1

@abn abn closed this as completed May 10, 2022
@abn abn reopened this May 10, 2022
@lafrenierejm
Copy link
Contributor

Anecdotally, I have never seen this error in Poetry 1.2.0b1 in the several weeks that my team at work has been using 1.2.0b1 both locally and in CI for multiple repos.

@neersighted
Copy link
Member

Not sure why this was re-opened, but I am closing it as there have been no consistent reproductions on 1.2.0 -- please open a new issue if you are able to reproduce installer issues with 1.2.0.

@mkniewallner mkniewallner removed the status/triage This issue needs to be triaged label Sep 18, 2022
joakimnordling added a commit to ioxiocom/docker-images that referenced this issue May 26, 2023
I believe the commented out code was related to this:  python-poetry/poetry#3336 (comment)

The code has been in commented out state for a long time and poetry 1.5.0 does no longer even support the option, so better clean up this old junk.
joakimnordling added a commit to ioxiocom/docker-images that referenced this issue May 26, 2023
I believe the commented out code was related to this: python-poetry/poetry#3336 (comment)

The code has been in commented out state for a long time and poetry 1.5.0 does no longer even support the option, so better clean up this old junk.
Copy link

github-actions bot commented Mar 1, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests