robertmartin8 / PyPortfolioOpt

Financial portfolio optimisation in python, including classical efficient frontier, Black-Litterman, Hierarchical Risk Parity
https://pyportfolioopt.readthedocs.io/
MIT License
4.24k stars 927 forks source link

Could not install on MacOS Ventura 13.2.1 #561

Closed Fabioozen closed 7 months ago

Fabioozen commented 9 months ago

Operating system, environment, python version MacOS chip M2, visual studio venv, python3.8.10

What you tried pip install pyportfolioopt

Error message

Collecting pyportfolioopt
  Using cached pyportfolioopt-1.5.5-py3-none-any.whl (61 kB)
Collecting cvxpy<2.0.0,>=1.1.19 (from pyportfolioopt)
  Obtaining dependency information for cvxpy<2.0.0,>=1.1.19 from https://files.pythonhosted.org/packages/c0/bb/4af694fb782bb92747dea6a8e57cb92ccd9a6518d0ed558fe53aa47c3baa/cvxpy-1.3.2-cp38-cp38-macosx_10_9_universal2.whl.metadata
  Using cached cvxpy-1.3.2-cp38-cp38-macosx_10_9_universal2.whl.metadata (8.7 kB)
Requirement already satisfied: numpy<2.0.0,>=1.22.4 in ./.venv/lib/python3.8/site-packages (from pyportfolioopt) (1.24.4)
Requirement already satisfied: pandas>=0.19 in ./.venv/lib/python3.8/site-packages (from pyportfolioopt) (2.0.3)
Requirement already satisfied: scipy<2.0,>=1.3 in ./.venv/lib/python3.8/site-packages (from pyportfolioopt) (1.10.1)
Collecting osqp>=0.4.1 (from cvxpy<2.0.0,>=1.1.19->pyportfolioopt)
  Using cached osqp-0.6.3.tar.gz (228 kB)
  Installing build dependencies ... error
  error: subprocess-exited-with-error

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [111 lines of output]
      Collecting oldest-supported-numpy
        Obtaining dependency information for oldest-supported-numpy from https://files.pythonhosted.org/packages/94/9a/756fef9346e5ca2289cb70d73990b4c9f25446a885c1186cfb93a85e7da0/oldest_supported_numpy-2023.8.3-py3-none-any.whl.metadata
        Using cached oldest_supported_numpy-2023.8.3-py3-none-any.whl.metadata (9.5 kB)
      Collecting setuptools>=40.8.0
        Obtaining dependency information for setuptools>=40.8.0 from https://files.pythonhosted.org/packages/bb/26/7945080113158354380a12ce26873dd6c1ebd88d47f5bc24e2c5bb38c16a/setuptools-68.2.2-py3-none-any.whl.metadata
        Using cached setuptools-68.2.2-py3-none-any.whl.metadata (6.3 kB)
      Collecting wheel
        Obtaining dependency information for wheel from https://files.pythonhosted.org/packages/b8/8b/31273bf66016be6ad22bb7345c37ff350276cfd46e389a0c2ac5da9d9073/wheel-0.41.2-py3-none-any.whl.metadata
        Using cached wheel-0.41.2-py3-none-any.whl.metadata (2.2 kB)
      Collecting setuptools_scm>=6.2
        Obtaining dependency information for setuptools_scm>=6.2 from https://files.pythonhosted.org/packages/ca/04/4ea91c627355ae6d976bf7f1fc2815372a96b1b87bf290c8d726d10a08a1/setuptools_scm-8.0.3-py3-none-any.whl.metadata
        Using cached setuptools_scm-8.0.3-py3-none-any.whl.metadata (6.1 kB)
      Collecting qdldl
        Using cached qdldl-0.1.7.post0.tar.gz (70 kB)
        Installing build dependencies: started
        Installing build dependencies: finished with status 'done'
        Getting requirements to build wheel: started
        Getting requirements to build wheel: finished with status 'done'
        Installing backend dependencies: started
        Installing backend dependencies: finished with status 'done'
        Preparing metadata (pyproject.toml): started
        Preparing metadata (pyproject.toml): finished with status 'done'
      Collecting numpy==1.21.0 (from oldest-supported-numpy)
        Using cached numpy-1.21.0-cp38-cp38-macosx_11_0_arm64.whl (12.1 MB)
      Collecting packaging>=20 (from setuptools_scm>=6.2)
        Using cached packaging-23.1-py3-none-any.whl (48 kB)
      Collecting tomli>=1 (from setuptools_scm>=6.2)
        Using cached tomli-2.0.1-py3-none-any.whl (12 kB)
      Collecting typing-extensions (from setuptools_scm>=6.2)
        Obtaining dependency information for typing-extensions from https://files.pythonhosted.org/packages/24/21/7d397a4b7934ff4028987914ac1044d3b7d52712f30e2ac7a2ae5bc86dd0/typing_extensions-4.8.0-py3-none-any.whl.metadata
        Using cached typing_extensions-4.8.0-py3-none-any.whl.metadata (3.0 kB)
      Collecting scipy>=0.13.2 (from qdldl)
        Using cached scipy-1.10.1-cp38-cp38-macosx_12_0_arm64.whl (28.8 MB)
      Using cached oldest_supported_numpy-2023.8.3-py3-none-any.whl (4.8 kB)
      Using cached setuptools-68.2.2-py3-none-any.whl (807 kB)
      Using cached wheel-0.41.2-py3-none-any.whl (64 kB)
      Using cached setuptools_scm-8.0.3-py3-none-any.whl (41 kB)
      Using cached typing_extensions-4.8.0-py3-none-any.whl (31 kB)
      Building wheels for collected packages: qdldl
        Building wheel for qdldl (pyproject.toml): started
        Building wheel for qdldl (pyproject.toml): finished with status 'error'
        error: subprocess-exited-with-error

        × Building wheel for qdldl (pyproject.toml) did not run successfully.
        │ exit code: 1
        ╰─> [59 lines of output]
            running bdist_wheel
            running build
            running build_ext
            Traceback (most recent call last):
              File "/Users/fabio/Desktop/PROGRAMMAZIONE/Finance/.venv/bin/cmake", line 5, in <module>
                from cmake import cmake
            ModuleNotFoundError: No module named 'cmake'
            Traceback (most recent call last):
              File "/Users/fabio/Desktop/PROGRAMMAZIONE/Finance/.venv/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
                main()
              File "/Users/fabio/Desktop/PROGRAMMAZIONE/Finance/.venv/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/fabio/Desktop/PROGRAMMAZIONE/Finance/.venv/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
                return _build_backend().build_wheel(wheel_directory, config_settings,
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 434, in build_wheel
                return self._build_with_temp_dir(
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 419, in _build_with_temp_dir
                self.run_setup()
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 341, in run_setup
                exec(code, locals())
              File "<string>", line 113, in <module>
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/__init__.py", line 103, in setup
                return distutils.core.setup(**attrs)
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 185, in setup
                return run_commands(dist)
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
                dist.run_commands()
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
                self.run_command(cmd)
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/dist.py", line 989, in run_command
                super().run_command(command)
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
                cmd_obj.run()
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/normal/lib/python3.8/site-packages/wheel/bdist_wheel.py", line 364, in run
                self.run_command("build")
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
                self.distribution.run_command(command)
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/dist.py", line 989, in run_command
                super().run_command(command)
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
                cmd_obj.run()
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/_distutils/command/build.py", line 131, in run
                self.run_command(cmd_name)
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
                self.distribution.run_command(command)
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/dist.py", line 989, in run_command
                super().run_command(command)
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
                cmd_obj.run()
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/command/build_ext.py", line 88, in run
                _build_ext.run(self)
              File "/private/var/folders/b8/br7148js32ddy47zfy_ztkm00000gn/T/pip-build-env-041ywij9/overlay/lib/python3.8/site-packages/setuptools/_distutils/command/build_ext.py", line 345, in run
                self.build_extensions()
              File "<string>", line 81, in build_extensions
              File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 415, in check_output
                return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
              File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 516, in run
                raise CalledProcessError(retcode, process.args,
            subprocess.CalledProcessError: Command '['cmake', '--version']' returned non-zero exit status 1.
            [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed building wheel for qdldl
      Failed to build qdldl
      ERROR: Could not build wheels for qdldl, which is required to install pyproject.toml-based projects
      [end of output]

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

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

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

I'm a newbie in this field, but I followed most of the answers on this page as well as StackOverflow regarding this issue. I created a venv, installed Xcode, Cmake, as well as other python packages; I've been trying to solve this issue for a week :(

Thank you in advance for your support!

88d52bdba0366127fffca9dfa93895 commented 9 months ago

Hi @Fabioozen, the error said you dont have cmake, you could try pip install cmake then install this library. Let me know if you still have any question.

Fabioozen commented 9 months ago
pip install cmake
Requirement already satisfied: cmake in ./.venv/lib/python3.8/site-packages (3.27.5)

I tried running again pip install pyportfolioopt just in case, but It's giving me the same exact error.

88d52bdba0366127fffca9dfa93895 commented 9 months ago

maybe uninstall cmake then reinstall pypopt, your problem similar to this SO https://stackoverflow.com/a/73382564

Fabioozen commented 9 months ago

Thanks for the quick reply.

I did what you suggested and it doesn'work: after pip uninstall cmake with success, pip install cmake with success, pip install pyportfolioopt resulted in the same error. I re-tried the process with both pip3 uninstall and install just in case.

I wonder if osqp and cvxpy play a role in the issue...

Nothing works 😭

88d52bdba0366127fffca9dfa93895 commented 9 months ago

maybe this will work: pip3 uninstall cmake, and then retry installing the original library: pip3 install pyportfolioopt @Fabioozen please try that and dont install pip install cmake

Fabioozen commented 9 months ago

As I said, I already tried pip3 uninstall and install

88d52bdba0366127fffca9dfa93895 commented 9 months ago

I mean you could try these 2 steps:

pip3 uninstall cmake
pip install pyportfolioopt

instead of 3 steps in your comment:

pip3 uninstall cmake
pip install cmake
pip install pyportfolioopt

Thanks for the quick reply.

I did what you suggested and it doesn'work: after pip uninstall cmake with success, pip install cmake with success, pip install pyportfolioopt resulted in the same error. I re-tried the process with both pip3 uninstall and install just in case.

I wonder if osqp and cvxpy play a role in the issue...

Nothing works 😭

Fabioozen commented 9 months ago

Doesn't work, just tried.

88d52bdba0366127fffca9dfa93895 commented 8 months ago

It's strange for me, if you could fix this issue by any method, please let me know and close this issue. Thanks you.

meshudn commented 8 months ago

This is a mac os related problem. I solved the problem by installing cmake using brew with the platform.

arch -arm64 brew install cmake

Then: pip install pyportfolioopt

deanerfree commented 8 months ago

Thanks @meshudn I had the same problems as above and did

brew install cmake
pip install pyportfolioopt

Success