pythonscipygensim

Pip install gensim is not working. Error in generation metadata for scipy


I am trying to install gensim to do some topic modelling. But I keep having the same problem, which is that it can't prepare metadata when collecting from scipy. I hope maybe you guys can help.

Here is the error-code when I write "pip install gensim":

Collecting gensim
  Using cached gensim-4.3.3.tar.gz (23.3 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting numpy<2.0,>=1.18.5 (from gensim)
  Using cached numpy-1.26.4.tar.gz (15.8 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Collecting scipy<1.14.0,>=1.7.0 (from gensim)
  Using cached scipy-1.13.1.tar.gz (57.2 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [47 lines of output]
      + meson setup C:\Users\chris\AppData\Local\Temp\pip-install-w3xvcmvu\scipy_eadead623c7d42e18d122f751d3d943b C:\Users\chris\AppData\Local\Temp\pip-install-w3xvcmvu\scipy_eadead623c7d42e18d122f751d3d943b\.mesonpy-sycykl_n -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=C:\Users\chris\AppData\Local\Temp\pip-install-w3xvcmvu\scipy_eadead623c7d42e18d122f751d3d943b\.mesonpy-sycykl_n\meson-python-native-file.ini
      The Meson build system
      Version: 1.8.3
      Source dir: C:\Users\chris\AppData\Local\Temp\pip-install-w3xvcmvu\scipy_eadead623c7d42e18d122f751d3d943b
      Build dir: C:\Users\chris\AppData\Local\Temp\pip-install-w3xvcmvu\scipy_eadead623c7d42e18d122f751d3d943b\.mesonpy-sycykl_n
      Build type: native build
      Activating VS 17.14.10
      Project name: scipy
      Project version: 1.13.1
      C compiler for the host machine: cl (msvc 19.44.35213 "Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35213 for x64")
      C linker for the host machine: link link 14.44.35213.0
      C++ compiler for the host machine: cl (msvc 19.44.35213 "Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35213 for x64")
      C++ linker for the host machine: link link 14.44.35213.0
      Cython compiler for the host machine: cython (cython 3.0.12)
      Host machine cpu family: x86_64
      Host machine cpu: x86_64
      Program python found: YES (C:\Users\chris\anaconda3\python.exe)
      Run-time dependency python found: YES 3.13
      Program cython found: YES (C:\Users\chris\AppData\Local\Temp\pip-build-env-yrm26wax\overlay\Scripts\cython.EXE)
      Compiler for C supports arguments -Wno-unused-but-set-variable: NO
      Compiler for C supports arguments -Wno-unused-function: NO
      Compiler for C supports arguments -Wno-conversion: NO
      Compiler for C supports arguments -Wno-misleading-indentation: NO
      Library m found: NO

      ..\meson.build:78:0: ERROR: Unknown compiler(s): [['ifort'], ['gfortran'], ['flang-new'], ['flang'], ['pgfortran'], ['g95']]
      The following exception(s) were encountered:
      Running `ifort --help` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `ifort --version` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `ifort -V` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `gfortran --help` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `gfortran --version` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `gfortran -V` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `flang-new --help` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `flang-new --version` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `flang-new -V` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `flang --help` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `flang --version` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `flang -V` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `pgfortran --help` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `pgfortran --version` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `pgfortran -V` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `g95 --help` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `g95 --version` gave "[WinError 2] Den angivne fil blev ikke fundet"
      Running `g95 -V` gave "[WinError 2] Den angivne fil blev ikke fundet"

      A full log can be found at C:\Users\chris\AppData\Local\Temp\pip-install-w3xvcmvu\scipy_eadead623c7d42e18d122f751d3d943b\.mesonpy-sycykl_n\meson-logs\meson-log.txt
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

I have tried these things because other people have similar problems:


Solution

  • If I understand your build log correctly, you are trying to build SciPy 1.13.1 on Python 3.13. It is trying to install this old version of SciPy because gensim requires SciPy < 1.14.0.

    Gensim requires this old version of SciPy because it makes use of one of SciPy's private APIs, which was deprecated in SciPy 0.14.0, and which was moved in SciPy 1.14.0. There aren't any builds of SciPy 1.13.x for that version because Python 3.13 was not supported on that version of SciPy. See Toolchain Roadmap.

    For that reason, it's trying to build from source, and failing, because you don't have a Fortran compiler installed.

    You have three options:

    1. Use Python 3.12, or an older version that is supported by SciPy 1.13.1.
    2. Build SciPy 1.13.1 from source. A guide on this can be found here. I will warn you that building SciPy on Windows is quite tricky at the best of times, and that you might be the first person to try building such an old version of SciPy on such a new version of Python.
    3. Fix gensim to work with newer versions of SciPy. You can see a discussion of this on the gensim issue tracker here.