lyst / lightfm

A Python implementation of LightFM, a hybrid recommendation algorithm.
Apache License 2.0
4.66k stars 679 forks source link

Can't install on Python 3.10.6 in Ubuntu #703

Open guilhermeparreira opened 8 months ago

guilhermeparreira commented 8 months ago

Hi there!

I couldn't install the package on my machine (Python 3.10.6 and Ubuntu 22.04.

See the following:

(omnisales-ml) guilherme@FEL0987:~/omnisales-ml$ pipenv install lightfm --skip-lock
Installing lightfm...
Resolving lightfm...
Installing...
⠋ Installing lightfm...[31m[1mError: [0m An error occurred while installing [32mlightfm[0m!
Error text: Collecting lightfm
  Downloading lightfm-1.17.tar.gz (316 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 316.4/316.4 kB 2.0 MB/s eta 0:00:00
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Requirement already satisfied: numpy in /home/guilherme/.local/share/virtualenvs/omnisales-ml-0XALTDrq/lib/python3.10/site-packages (from lightfm->-r /tmp/pipenv-pp2v0p94-requirements/pipenv-ri820uun-requirement.txt (line 1)) (1.26.1)
Requirement already satisfied: scipy>=0.17.0 in /home/guilherme/.local/share/virtualenvs/omnisales-ml-0XALTDrq/lib/python3.10/site-packages (from lightfm->-r /tmp/pipenv-pp2v0p94-requirements/pipenv-ri820uun-requirement.txt (line 1)) (1.11.3)
Requirement already satisfied: requests in /home/guilherme/.local/share/virtualenvs/omnisales-ml-0XALTDrq/lib/python3.10/site-packages (from lightfm->-r /tmp/pipenv-pp2v0p94-requirements/pipenv-ri820uun-requirement.txt (line 1)) (2.31.0)
Collecting scikit-learn
  Downloading scikit_learn-1.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.8/10.8 MB 2.7 MB/s eta 0:00:00
Requirement already satisfied: idna<4,>=2.5 in /home/guilherme/.local/share/virtualenvs/omnisales-ml-0XALTDrq/lib/python3.10/site-packages (from requests->lightfm->-r /tmp/pipenv-pp2v0p94-requirements/pipenv-ri820uun-requirement.txt (line 1)) (3.4)
Requirement already satisfied: certifi>=2017.4.17 in /home/guilherme/.local/share/virtualenvs/omnisales-ml-0XALTDrq/lib/python3.10/site-packages (from requests->lightfm->-r /tmp/pipenv-pp2v0p94-requirements/pipenv-ri820uun-requirement.txt (line 1)) (2023.7.22)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/guilherme/.local/share/virtualenvs/omnisales-ml-0XALTDrq/lib/python3.10/site-packages (from requests->lightfm->-r /tmp/pipenv-pp2v0p94-requirements/pipenv-ri820uun-requirement.txt (line 1)) (3.3.1)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/guilherme/.local/share/virtualenvs/omnisales-ml-0XALTDrq/lib/python3.10/site-packages (from requests->lightfm->-r /tmp/pipenv-pp2v0p94-requirements/pipenv-ri820uun-requirement.txt (line 1)) (2.0.7)
Collecting threadpoolctl>=2.0.0
  Using cached threadpoolctl-3.2.0-py3-none-any.whl (15 kB)
Requirement already satisfied: joblib>=1.1.1 in /home/guilherme/.local/share/virtualenvs/omnisales-ml-0XALTDrq/lib/python3.10/site-packages (from scikit-learn->lightfm->-r /tmp/pipenv-pp2v0p94-requirements/pipenv-ri820uun-requirement.txt (line 1)) (1.3.2)
Building wheels for collected packages: lightfm
  Building wheel for lightfm (setup.py): started
  Building wheel for lightfm (setup.py): finished with status 'error'
  Running setup.py clean for lightfm
Failed to build lightfm
Installing collected packages: threadpoolctl, scikit-learn, lightfm
  Running setup.py install for lightfm: started
  Running setup.py install for lightfm: finished with status 'error'

[36m  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [46 lines of output]
      /home/guilherme/.local/share/virtualenvs/omnisales-ml-0XALTDrq/lib/python3.10/site-packages/setuptools/dist.py:498: SetuptoolsDeprecationWarning: Invalid dash-separated options
      !!

              ********************************************************************************
              Usage of dash-separated 'description-file' will not be supported in future
              versions. Please use the underscore name 'description_file' instead.

              This deprecation is overdue, please update your project and remove deprecated
              calls to avoid build errors in the future.

              See https://setuptools.pypa.io/en/latest/userguide/declarative_config.html for details.
              ********************************************************************************

      !!
        opt = self.warn_dash_deprecation(opt, section)
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-310
      creating build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/_lightfm_fast.py -> build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/data.py -> build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/lightfm.py -> build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/evaluation.py -> build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/cross_validation.py -> build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/__init__.py -> build/lib.linux-x86_64-cpython-310/lightfm
      creating build/lib.linux-x86_64-cpython-310/lightfm/datasets
      copying lightfm/datasets/movielens.py -> build/lib.linux-x86_64-cpython-310/lightfm/datasets
      copying lightfm/datasets/stackexchange.py -> build/lib.linux-x86_64-cpython-310/lightfm/datasets
      copying lightfm/datasets/_common.py -> build/lib.linux-x86_64-cpython-310/lightfm/datasets
      copying lightfm/datasets/__init__.py -> build/lib.linux-x86_64-cpython-310/lightfm/datasets
      copying lightfm/_lightfm_fast_no_openmp.c -> build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/_lightfm_fast_openmp.c -> build/lib.linux-x86_64-cpython-310/lightfm
      warning: build_py: byte-compiling is disabled, skipping.

      running build_ext
      building 'lightfm._lightfm_fast_openmp' extension
      creating build/temp.linux-x86_64-cpython-310
      creating build/temp.linux-x86_64-cpython-310/lightfm
      x86_64-linux-gnu-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/home/guilherme/.local/share/virtualenvs/omnisales-ml-0XALTDrq/include -I/usr/include/python3.10 -c lightfm/_lightfm_fast_openmp.c 
-o build/temp.linux-x86_64-cpython-310/lightfm/_lightfm_fast_openmp.o -ffast-math -march=native -fopenmp
      lightfm/_lightfm_fast_openmp.c:22:10: fatal error: Python.h: No such file or directory
         22 | #include "Python.h"
            |          ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for lightfm
  error: subprocess-exited-with-error

  × Running setup.py install for lightfm did not run successfully.
  │ exit code: 1
  ╰─> [59 lines of output]
      /home/guilherme/.local/share/virtualenvs/omnisales-ml-0XALTDrq/lib/python3.10/site-packages/setuptools/dist.py:498: SetuptoolsDeprecationWarning: Invalid dash-separated options
      !!

              ********************************************************************************
              Usage of dash-separated 'description-file' will not be supported in future
              versions. Please use the underscore name 'description_file' instead.

              This deprecation is overdue, please update your project and remove deprecated
              calls to avoid build errors in the future.

              See https://setuptools.pypa.io/en/latest/userguide/declarative_config.html for details.
              ********************************************************************************

      !!
        opt = self.warn_dash_deprecation(opt, section)
      running install
      /home/guilherme/.local/share/virtualenvs/omnisales-ml-0XALTDrq/lib/python3.10/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
      !!

              ********************************************************************************
              Please avoid running ``setup.py`` directly.
              Instead, use pypa/build, pypa/installer or other
              standards-based tools.

              See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
              ********************************************************************************

      !!
        self.initialize_options()
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-310
      creating build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/_lightfm_fast.py -> build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/data.py -> build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/lightfm.py -> build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/evaluation.py -> build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/cross_validation.py -> build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/__init__.py -> build/lib.linux-x86_64-cpython-310/lightfm
      creating build/lib.linux-x86_64-cpython-310/lightfm/datasets
      copying lightfm/datasets/movielens.py -> build/lib.linux-x86_64-cpython-310/lightfm/datasets
      copying lightfm/datasets/stackexchange.py -> build/lib.linux-x86_64-cpython-310/lightfm/datasets
      copying lightfm/datasets/_common.py -> build/lib.linux-x86_64-cpython-310/lightfm/datasets
      copying lightfm/datasets/__init__.py -> build/lib.linux-x86_64-cpython-310/lightfm/datasets
      copying lightfm/_lightfm_fast_no_openmp.c -> build/lib.linux-x86_64-cpython-310/lightfm
      copying lightfm/_lightfm_fast_openmp.c -> build/lib.linux-x86_64-cpython-310/lightfm
      warning: build_py: byte-compiling is disabled, skipping.

      running build_ext
      building 'lightfm._lightfm_fast_openmp' extension
      creating build/temp.linux-x86_64-cpython-310
      creating build/temp.linux-x86_64-cpython-310/lightfm
      x86_64-linux-gnu-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/home/guilherme/.local/share/virtualenvs/omnisales-ml-0XALTDrq/include -I/usr/include/python3.10 -c lightfm/_lightfm_fast_openmp.c 
-o build/temp.linux-x86_64-cpython-310/lightfm/_lightfm_fast_openmp.o -ffast-math -march=native -fopenmp
      lightfm/_lightfm_fast_openmp.c:22:10: fatal error: Python.h: No such file or directory
         22 | #include "Python.h"
            |          ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> lightfm

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
[0m
⠙ Installing lightfm...✘ Installation Failed
(omnisales-ml) guilherme@FEL0987:~/omnisales-ml$ 

what can I do?

georgepglv commented 6 months ago

I was having the same problem and got it to work based on this: https://stackoverflow.com/questions/41492878/command-x86-64-linux-gnu-gcc-failed-with-exit-status-1

Run the accepted answer in "full mode", without any venv. Then simply try reinstalling LightFM again