causalml icon indicating copy to clipboard operation
causalml copied to clipboard

Problem with installing the causalml library

Open mwasielewski15 opened this issue 3 years ago • 1 comments

Describe the bug I am trying to install causalml package both using pip and from source following these instructions: https://causalml.readthedocs.io/en/latest/installation.html Unfortunately I cannot succeed with building wheel for causalml (screenshot below). It looks like there is a problem with setup.py file which is part of repository I had to clone (according to the installation instructions). I've also installed Microsoft Visual C++ as it's suggested in error but it didn't change anything.

To Reproduce $ git clone https://github.com/uber/causalml.git $ cd causalml $ pip install -r requirements.txt $ pip install causalml <- after this command I get an error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots image

Environment (please complete the following information):

  • Windows
  • Python 3.10
  • Versions of Major Dependencies : according to requirements.txt from repository https://github.com/uber/causalml.git

mwasielewski15 avatar Aug 11 '22 12:08 mwasielewski15

Hi, in WIndows OS case check that:

  • MSVC++ is in Path environment variable
  • 80 lines of further output doesn't contain errors of finding C/C++ headers

alexander-pv avatar Aug 13 '22 23:08 alexander-pv

FYI I'm facing the same issues on a different system, tested building with 0.13.0 and current 0.14.0 but both are breaking with different errors. I'm not sure if this is a Cython specific issue, but I made a change to the build file of init_capacity = (2 ** (tree.max_depth + 1)) - 1 and it built fine, raising a PR to test build success w/ GHA.

Environment

  • MacOS Ventura 13.4.1 - M1
  • Python 3.8/3.9 (both installed with conda env create -f environment-py3*.yml)
  • Versions of major dependencies - See above
(causalml-py38) ➜  causalml git:(v0.13.0) pip install .
Processing /Users/benjaminsaunders/Documents/Marketing/causalml
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [62 lines of output]
      warning: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_tree.pxd:61:73: 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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_tree.pxd:62:59: 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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_tree.pxd:63:63: 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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_splitter.pxd:84:72: 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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_splitter.pxd:89:68: 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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_criterion.pxd:57: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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_criterion.pxd:58: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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_criterion.pxd:59: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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_criterion.pxd:60: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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_utils.pxd:49: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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_utils.pxd:87: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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_utils.pxd:119: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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_utils.pxd:137: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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_utils.pxd:139: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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_utils.pxd:160: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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/tree/_utils.pxd:161: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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/neighbors/_quad_tree.pxd:72:59: 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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/neighbors/_quad_tree.pxd:91:51: 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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/neighbors/_quad_tree.pxd:94:59: 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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/neighbors/_quad_tree.pxd:95:63: 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: /private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/sklearn/neighbors/_quad_tree.pxd:96:80: 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: causalml/inference/tree/causal/_builder.pyx:185: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: causalml/inference/tree/causal/_builder.pyx:331: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.
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
      
              # Initial capacity
              cdef int init_capacity
      
              if tree.max_depth <= 10:
                  init_capacity = (2 ** (tree.max_depth + 1)) - 1
                                                              ^
      ------------------------------------------------------------
      
      causalml/inference/tree/causal/_builder.pyx:61:56: Cannot assign type 'double' to 'int'
      Compiling causalml/inference/tree/causal/_criterion.pyx because it changed.
      Compiling causalml/inference/tree/causal/_builder.pyx because it changed.
      Compiling causalml/inference/tree/uplift.pyx because it changed.
      [1/3] Cythonizing causalml/inference/tree/causal/_builder.pyx
      Traceback (most recent call last):
        File "/Users/benjaminsaunders/miniconda3/envs/causalml-py38/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/Users/benjaminsaunders/miniconda3/envs/causalml-py38/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/Users/benjaminsaunders/miniconda3/envs/causalml-py38/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
        File "/private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
          self.run_setup()
        File "/private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 487, in run_setup
          super(_BuildMetaLegacyBackend,
        File "/private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 338, in run_setup
          exec(code, locals())
        File "<string>", line 46, in <module>
        File "/private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/Cython/Build/Dependencies.py", line 1134, in cythonize
          cythonize_one(*args)
        File "/private/var/folders/ck/8kpq2yv50h18k9z3jwktl1gm0000gp/T/pip-build-env-1tpq9b41/overlay/lib/python3.8/site-packages/Cython/Build/Dependencies.py", line 1301, in cythonize_one
          raise CompileError(None, pyx_file)
      Cython.Compiler.Errors.CompileError: causalml/inference/tree/causal/_builder.pyx
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

bsaunders27 avatar Jul 17 '23 18:07 bsaunders27

Ran into this issue this morning and created a fix and found the first issue that matched. Looks like you already have a fix though!

mingchun-liu avatar Jul 18 '23 22:07 mingchun-liu

Hi all, the root cause of types issue in builder.pyx is recent cython updates.

Pyproject.toml has no upper bound for cython version( cython>=0.28.0)

Manual type casting may lead to segfaults despite successfull package installation. I would run all related tests first and maybe introduced some more of them just to make sure that such change is correct.

Reliable solution: #640

alexander-pv avatar Jul 19 '23 05:07 alexander-pv

We just merged #640 by @alexander-pv. @mwasielewski15, @bsaunders27, @mlsquareup, could you try it again with the lastest master?

$ pip uninstall causalml
$ git clone https://github.com/uber/causalml.git
$ cd causalml
$ pip install -r requirements.txt
$ pip install .

jeongyoonlee avatar Jul 19 '23 17:07 jeongyoonlee

Thanks @jeongyoonlee looks like this worked! I'll go ahead and revert on #641, looks like it's still needed for the numpy version upgrade to fix on the conda build for M1 but lower priority given pip install is now working 🙂

bsaunders27 avatar Jul 20 '23 02:07 bsaunders27

We also merged #641 by @bsaunders27. Conda installation with environment files should work now as well.

@mwasielewski15, @mlsquareup, can you check if the latest master works for you? If it does, we will release 0.14.1 with the fix soon.

jeongyoonlee avatar Jul 20 '23 16:07 jeongyoonlee