MaartenGr / BERTopic

Leveraging BERT and c-TF-IDF to create easily interpretable topics.
https://maartengr.github.io/BERTopic/
MIT License
6.19k stars 765 forks source link

Installation of BERTopic fails due to llvmlite version compatibility with Python 3.12 (macOS M1) #2141

Closed iamvarol closed 2 months ago

iamvarol commented 2 months ago

Have you searched existing issues? πŸ”Ž

Desribe the bug

First of all, amazing library. Kudos!

I'm trying to install BERTopic on macOS (M1 chipset) with Python version 3.12. However, the installation fails due to a compatibility issue with llvmlite==0.36.0. The error indicates that the build_wheel() process cannot complete, and the package has a version requirement that is not compatible with Python 3.12.5. Below is the error log:

error: Failed to prepare distributions
  Caused by: Failed to fetch wheel: llvmlite==0.36.0
  Caused by: Build backend failed to determine extra requires with `build_wheel()` with exit status: 1
--- stdout:

--- stderr:
Traceback (most recent call last):
  File "<string>", line 14, in <module>
  File "/Users/user_name/.cache/uv/builds-v0/.tmp1cVMU9/lib/python3.12/site-packages/setuptools/build_meta.py", line 332, in get_requires_for_build_wheel
    return self._get_build_requires(config_settings, requirements=[])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/.cache/uv/builds-v0/.tmp1cVMU9/lib/python3.12/site-packages/setuptools/build_meta.py", line 302, in _get_build_requires
    self.run_setup()
  File "/Users/user_name/.cache/uv/builds-v0/.tmp1cVMU9/lib/python3.12/site-packages/setuptools/build_meta.py", line 503, in run_setup
    super().run_setup(setup_script=setup_script)
  File "/Users/user_name/.cache/uv/builds-v0/.tmp1cVMU9/lib/python3.12/site-packages/setuptools/build_meta.py", line 318, in run_setup
    exec(code, locals())
  File "<string>", line 55, in <module>
  File "<string>", line 52, in _guard_py_ver
RuntimeError: Cannot install on Python version 3.12.5; only versions >=3.6,<3.10 are supported.

Reproduction

pip install bertopic

BERTopic Version

bertopic 0.16.3 (latest)

iamvarol commented 2 months ago

here is the other error message when I tried to use poetry

poetry add bertopic                                          
Using version ^0.16.3 for bertopic

Updating dependencies
Resolving dependencies... (1.8s)

Package operations: 43 installs, 0 updates, 0 removals

  β€’ Installing certifi (2024.8.30)
  β€’ Installing charset-normalizer (3.3.2)
  β€’ Installing idna (3.8)
  β€’ Installing urllib3 (2.2.2)
  β€’ Installing filelock (3.16.0)
  β€’ Installing fsspec (2024.9.0)
  β€’ Installing numpy (2.1.1)
  β€’ Installing packaging (24.1)
  β€’ Installing pyyaml (6.0.2)
  β€’ Installing requests (2.32.3)
  β€’ Installing tqdm (4.66.5)
  β€’ Installing typing-extensions (4.12.2)
  β€’ Installing huggingface-hub (0.24.6)
  β€’ Installing joblib (1.4.2)
  β€’ Installing llvmlite (0.34.0): Failed

  ChefBuildError

  Backend subprocess exited when trying to invoke build_wheel

  running bdist_wheel
  /private/var/folders/r1/5ys7t2sj2h75g8y4tb9cqgrm0000gn/T/tmp85hxjt4s/.venv/bin/python /private/var/folders/r1/5ys7t2sj2h75g8y4tb9cqgrm0000gn/T/tmpf3ezygxl/llvmlite-0.34.0/ffi/build.py
  LLVM version... 18.1.8

  Traceback (most recent call last):
    File "/private/var/folders/r1/5ys7t2sj2h75g8y4tb9cqgrm0000gn/T/tmpf3ezygxl/llvmlite-0.34.0/ffi/build.py", line 191, in <module>
      main()
    File "/private/var/folders/r1/5ys7t2sj2h75g8y4tb9cqgrm0000gn/T/tmpf3ezygxl/llvmlite-0.34.0/ffi/build.py", line 185, in main
      main_posix('osx', '.dylib')
    File "/private/var/folders/r1/5ys7t2sj2h75g8y4tb9cqgrm0000gn/T/tmpf3ezygxl/llvmlite-0.34.0/ffi/build.py", line 143, in main_posix
      raise RuntimeError(msg)
  RuntimeError: Building llvmlite requires LLVM 10.0.x or 9.0.x, got '18.1.8'. Be sure to set LLVM_CONFIG to the right executable path.
  Read the documentation at http://llvmlite.pydata.org/ for more information about building llvmlite.

  error: command '/private/var/folders/r1/5ys7t2sj2h75g8y4tb9cqgrm0000gn/T/tmp85hxjt4s/.venv/bin/python' failed with exit code 1

  at ~/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/chef.py:164 in _prepare
      160β”‚ 
      161β”‚                 error = ChefBuildError("\n\n".join(message_parts))
      162β”‚ 
      163β”‚             if error is not None:
    β†’ 164β”‚                 raise error from None
      165β”‚ 
      166β”‚             return path
      167β”‚ 
      168β”‚     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with llvmlite (0.34.0) not supporting PEP 517 builds. You can verify this by running 'pip wheel --no-cache-dir --use-pep517 "llvmlite (==0.34.0)"'.

  β€’ Installing markupsafe (2.1.5)
  β€’ Installing mpmath (1.3.0)
  β€’ Installing scipy (1.14.1)
  β€’ Installing setuptools (74.1.2)
  β€’ Installing threadpoolctl (3.5.0)
MaartenGr commented 2 months ago

Thank you for sharing the extensive description. Unfortunately, I'm not on macOS so reproducing this is difficult for me. Having said that, it does seem like llvmlite is on v0.43.0 which might have fixed this. Any idea why your version is used? You can see this when installing BERTopic through pip.

iamvarol commented 2 months ago

Thank you for your quick response. I have already attempted to resolve the issue with the following actions:

brew install llvm
pip install --upgrade pip setuptools wheel
pip install llvmlite

After these steps, everything appeared to be okay as llvmlite==0.43.0 was successfully installed. However, when I attempted to re-install BERTopic, the same issue persisted, and llvmlite==0.36.0 was listed as a requirement, though I did not select that version.

Anyway, I will try to install on Ubuntu.