Yu-Group/iterative-Random-Forest

Error during install

Opened this issue · 2 comments

When trying to install the package from pip with **pip install irf** I get the following error message:

Collecting irf
Using cached irf-0.2.5.tar.gz (5.7 MB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [18 lines of output]
/tmp/pip-install-oseji12r/irf_482c5e8ee9a14698b37bd468cb6c6227/setup.py:8: DeprecationWarning:

    `numpy.distutils` is deprecated since NumPy 1.23.0, as a result
    of the deprecation of `distutils` itself. It will be removed for
    Python >= 3.12. For older Python versions it will remain present.
    It is recommended to use `setuptools < 60.0` for those Python versions.
    For more details, see:
      https://numpy.org/devdocs/reference/distutils_status_migration.html
  
  
    from numpy.distutils.core import setup
  Traceback (most recent call last):
    File "<string>", line 2, in <module>
    File "<pip-setuptools-caller>", line 34, in <module>
    File "/tmp/pip-install-oseji12r/irf_482c5e8ee9a14698b37bd468cb6c6227/setup.py", line 12, in <module>
      with open(path.join(path_to_repo, 'readme.md'), encoding='utf-8') as f:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-install-oseji12r/irf_482c5e8ee9a14698b37bd468cb6c6227/readme.md'
  [end of output]

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

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

When forking the repository and changing the README.md file with readme.md, we get past the base "no such file or directory" error. However, this then becomes a cython issue:

  Running command git clone --filter=blob:none --quiet https://github.com/LaneMatthewJ/iterative-Random-Forest.git /tmp/pip-install-tkwr6sf6/irf_1cdcbc2e98b04484bf5b91b95dd30a8e
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [201 lines of output]
      /tmp/pip-install-tkwr6sf6/irf_1cdcbc2e98b04484bf5b91b95dd30a8e/setup.py:8: DeprecationWarning:
      
        `numpy.distutils` is deprecated since NumPy 1.23.0, as a result
        of the deprecation of `distutils` itself. It will be removed for
        Python >= 3.12. For older Python versions it will remain present.
        It is recommended to use `setuptools < 60.0` for those Python versions.
        For more details, see:
          https://numpy.org/devdocs/reference/distutils_status_migration.html
      
      
        from numpy.distutils.core import setup
      Warning: Assuming default configuration (irf/ensemble/{setup_ensemble,setup}.py was not found)
      Warning: Assuming default configuration (irf/tests/{setup_tests,setup}.py was not found)
      /ccs/home/lanemj/conda/miniconda_frontier/lib/python3.10/site-packages/Cython/Compiler/Main.py:384: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /tmp/pip-install-tkwr6sf6/irf_1cdcbc2e98b04484bf5b91b95dd30a8e/irf/tree/_criterion.pxd
        tree = Parsing.p_module(s, pxd, full_module_name)
      warning: irf/tree/_criterion.pxd:58:45: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pxd:59:40: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pxd:60:48: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pxd:61:57: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:56:45: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:85:40: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:93:48: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:100:57: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:289:76: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:358:40: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:385:48: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:412:57: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:761:45: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:803:40: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:814:48: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:825:57: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:1256:45: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:1308:40: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:1340:48: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_criterion.pyx:1369:57: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_utils.pxd:46:75: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_utils.pxd:86:61: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_utils.pxd:118:56: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_utils.pxd:136:40: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_utils.pxd:138:71: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_utils.pxd:159:71: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: irf/tree/_utils.pxd:160:40: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
      
      # See _utils.pyx for details.
      
      import numpy as np
      cimport numpy as np
      from _tree cimport Node
      ^
      ------------------------------------------------------------
      
      irf/tree/_utils.pxd:13:0: '_tree.pxd' not found
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
      
      # See _utils.pyx for details.
      
      import numpy as np
      cimport numpy as np
      from _tree cimport Node
      ^
      ------------------------------------------------------------
      
      irf/tree/_utils.pxd:13:0: '_tree/Node.pxd' not found
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
          (SIZE_t*)
          (unsigned char*)
          (WeightedPQueueRecord*)
          (DOUBLE_t*)
          (DOUBLE_t**)
          (Node*)
           ^
      ------------------------------------------------------------
      
      irf/tree/_utils.pxd:41:5: 'Node' is not a type identifier
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
          (unsigned char*)
          (WeightedPQueueRecord*)
          (DOUBLE_t*)
          (DOUBLE_t**)
          (Node*)
          (Node**)
           ^
      ------------------------------------------------------------
      
      irf/tree/_utils.pxd:42:5: 'Node' is not a type identifier
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
          (unsigned char*)
          (WeightedPQueueRecord*)
          (DOUBLE_t*)
          (DOUBLE_t**)
          (Node*)
          (Node**)
          ^
      ------------------------------------------------------------
      
      irf/tree/_utils.pxd:42:4: Type specified multiple times
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              self.sum_total = NULL
              self.sum_left = NULL
              self.sum_right = NULL
              self.n_classes = NULL
      
              safe_realloc(&self.n_classes, n_outputs)
                          ^
      ------------------------------------------------------------
      
      irf/tree/_criterion.pyx:252:20: ambiguous overloaded method
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              # Allocate accumulators. Make sure they are NULL, not uninitialized,
              # before an exception can be raised (which triggers __dealloc__).
              self.node_medians = NULL
      
              # Allocate memory for the accumulators
              safe_realloc(&self.node_medians, n_outputs)
                          ^
      ------------------------------------------------------------
      
      irf/tree/_criterion.pyx:1245:20: ambiguous overloaded method
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              self.sum_total = NULL
              self.sum_left = NULL
              self.sum_right = NULL
              self.n_classes = NULL
      
              safe_realloc(&self.n_classes, n_outputs)
              ^
      ------------------------------------------------------------
      
      irf/tree/_criterion.pyx:252:8: Invalid use of fused types, type cannot be specialized
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              # Allocate accumulators. Make sure they are NULL, not uninitialized,
              # before an exception can be raised (which triggers __dealloc__).
              self.node_medians = NULL
      
              # Allocate memory for the accumulators
              safe_realloc(&self.node_medians, n_outputs)
              ^
      ------------------------------------------------------------
      
      irf/tree/_criterion.pyx:1245:8: Invalid use of fused types, type cannot be specialized
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-tkwr6sf6/irf_1cdcbc2e98b04484bf5b91b95dd30a8e/setup.py", line 40, in <module>
          setup(configuration=configuration,
        File "/ccs/home/lanemj/conda/miniconda_frontier/lib/python3.10/site-packages/numpy/distutils/core.py", line 135, in setup
          config = configuration()
        File "/tmp/pip-install-tkwr6sf6/irf_1cdcbc2e98b04484bf5b91b95dd30a8e/setup.py", line 29, in configuration
          config.add_subpackage('irf')
        File "/ccs/home/lanemj/conda/miniconda_frontier/lib/python3.10/site-packages/numpy/distutils/misc_util.py", line 1050, in add_subpackage
          config_list = self.get_subpackage(subpackage_name, subpackage_path,
        File "/ccs/home/lanemj/conda/miniconda_frontier/lib/python3.10/site-packages/numpy/distutils/misc_util.py", line 1016, in get_subpackage
          config = self._get_configuration_from_setup_py(
        File "/ccs/home/lanemj/conda/miniconda_frontier/lib/python3.10/site-packages/numpy/distutils/misc_util.py", line 958, in _get_configuration_from_setup_py
          config = setup_module.configuration(*args)
        File "/tmp/pip-install-tkwr6sf6/irf_1cdcbc2e98b04484bf5b91b95dd30a8e/irf/setup.py", line 26, in configuration
          config.ext_modules = cythonize(config.ext_modules)
        File "/ccs/home/lanemj/conda/miniconda_frontier/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1134, in cythonize
          cythonize_one(*args)
        File "/ccs/home/lanemj/conda/miniconda_frontier/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1301, in cythonize_one
          raise CompileError(None, pyx_file)
      Cython.Compiler.Errors.CompileError: irf/tree/_criterion.pyx
      Appending irf.tree configuration to irf
      Ignoring attempt to set 'name' (from 'irf' to 'irf.tree')
      Appending irf.ensemble configuration to irf
      Ignoring attempt to set 'name' (from 'irf' to 'irf.ensemble')
      Appending irf.tests configuration to irf
      Ignoring attempt to set 'name' (from 'irf' to 'irf.tests')
      Compiling irf/tree/_tree.pyx because it changed.
      Compiling irf/tree/_splitter.pyx because it changed.
      Compiling irf/tree/_criterion.pyx because it changed.
      Compiling irf/tree/_utils.pyx because it changed.
      [1/4] Cythonizing irf/tree/_criterion.pyx
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Clearly errors like irf/tree/_utils.pxd:13:0: '_tree.pxd' not found are problematic too, but at least we're getting somewhere (granted, _tree.pdx does exist, so I'm personally at a loss as well, but perhaps this helps in some way?

@zuegereliane - as it turns out the workaround is relatively straightforward enough. This all stems from an update to cython. From the scikit-learn issues page:

The solution is to pin cython to cython<3

SO, with all of that being said, here's how I did it:

# create the path to your environment and save as variable
mkdir -p ~/environments/conda/
PATH_TO_IRF_ENV=~/environments/conda/irf

# create and activate conda environment
conda create -p $PATH_TO_IRF_ENV -c conda-forge python=3.10
source activate $PATH_TO_IRF_ENV

# install older cython version
pip install "cython<3"
pip install "numpy<1.18" # imported in setup
pip install scipy==1.7
pip install --no-build-isolation irf@git+https://github.com/LaneMatthewJ/iterative-Random-Forest.git

edit: there were a few other requirements that I added to the setup.py*