convexfi / riskparity.py

Fast and scalable construction of risk parity portfolios
https://mirca.github.io/riskparity.py/
MIT License
285 stars 64 forks source link

Installation Problem #20

Closed ghost closed 1 year ago

ghost commented 1 year ago

Hi, I am trying to install riskparityportfolio using 'pip install riskparityportfolio'. I have installed Visual Studio Build Tools 2022. I am using python 3.10.4 and operating on Windows.

The error I received is:

Collecting riskparityportfolio
  Using cached riskparityportfolio-0.3.tar.gz (2.3 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [35 lines of output]
      C:\Users\me\anaconda3\envs\rp\lib\site-packages\setuptools\installer.py:27: SetuptoolsDeprecationWarning: setuptools.installer is deprecated. Requirements should be satisfied by a PEP 517 installer.
        warnings.warn(
      ERROR: Could not find a version that satisfies the requirement jaxlib (from versions: none)
      ERROR: No matching distribution found for jaxlib
      Traceback (most recent call last):
        File "C:\Users\me\anaconda3\envs\rp\lib\site-packages\setuptools\installer.py", line 82, in fetch_build_egg
          subprocess.check_call(cmd)
        File "C:\Users\me\anaconda3\envs\rp\lib\subprocess.py", line 369, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['C:\\Users\\me\\anaconda3\\envs\\rp\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\me\\AppData\\Local\\Temp\\tmpymv4g9nz', '--quiet', 'jaxlib']' returned non-zero exit status 1.

      The above exception was the direct cause of the following exception:

      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\me\AppData\Local\Temp\pip-install-yuxufr_s\riskparityportfolio_396a937d29af4587adae9b529b583849\setup.py", line 124, in <module>
          setup(
        File "C:\Users\me\anaconda3\envs\rp\lib\site-packages\setuptools\__init__.py", line 86, in setup
          _install_setup_requires(attrs)
        File "C:\Users\me\anaconda3\envs\rp\lib\site-packages\setuptools\__init__.py", line 80, in _install_setup_requires
          dist.fetch_build_eggs(dist.setup_requires)
        File "C:\Users\me\anaconda3\envs\rp\lib\site-packages\setuptools\dist.py", line 875, in fetch_build_eggs
          resolved_dists = pkg_resources.working_set.resolve(
        File "C:\Users\me\anaconda3\envs\rp\lib\site-packages\pkg_resources\__init__.py", line 789, in resolve
          dist = best[req.key] = env.best_match(
        File "C:\Users\me\anaconda3\envs\rp\lib\site-packages\pkg_resources\__init__.py", line 1075, in best_match
          return self.obtain(req, installer)
        File "C:\Users\me\anaconda3\envs\rp\lib\site-packages\pkg_resources\__init__.py", line 1087, in obtain
          return installer(requirement)
        File "C:\Users\me\anaconda3\envs\rp\lib\site-packages\setuptools\dist.py", line 945, in fetch_build_egg
          return fetch_build_egg(self, req)
        File "C:\Users\me\anaconda3\envs\rp\lib\site-packages\setuptools\installer.py", line 84, in fetch_build_egg
          raise DistutilsError(str(e)) from e
      distutils.errors.DistutilsError: Command '['C:\\Users\\me\\anaconda3\\envs\\rp\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\me\\AppData\\Local\\Temp\\tmpymv4g9nz', '--quiet', 'jaxlib']' 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: 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.

Do you have any advice on how to fix this and successfully install your great riskparityportfolio package?

Thank you

mirca commented 1 year ago

It looks like jaxlib may not be available for Python 3.10.4? Could you try pip install jaxlib?

ghost commented 1 year ago

Thanks. When I try pip install jaxlib I get the following error:

ERROR: Could not find a version that satisfies the requirement jaxlab (from versions: none)
ERROR: No matching distribution found for jaxlab
ghost commented 1 year ago

I was able to use this link here to install jax https://www.reddit.com/r/learnmachinelearning/comments/qnqdy0/jax_on_windows/

However, after having installed it and running pip install riskparityportfolio I unfortunately received another error:

        check.warn(importable)
      copying riskparityportfolio\vanilla.cpp -> build\lib.win-amd64-cpython-310\riskparityportfolio
      creating build\lib.win-amd64-cpython-310\riskparityportfolio\tests
      copying riskparityportfolio\tests\__init__.py -> build\lib.win-amd64-cpython-310\riskparityportfolio\tests
      copying riskparityportfolio\tests\test_modern_rpp.py -> build\lib.win-amd64-cpython-310\riskparityportfolio\tests
      copying riskparityportfolio\tests\test_vanilla_rpp.py -> build\lib.win-amd64-cpython-310\riskparityportfolio\tests
      running build_ext
      building 'riskparityportfolio.vanilla' extension
      creating build\temp.win-amd64-cpython-310
      creating build\temp.win-amd64-cpython-310\Release
      creating build\temp.win-amd64-cpython-310\Release\riskparityportfolio
      "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.33.31629\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -Ithird-party\eigen_3.3.7 -IC:\Users\me\anaconda3\envs\rpjax\lib\site-packages\pybind11\include -IC:\Users\me\anaconda3\envs\rpjax\lib\site-packages\pybind11\include -IC:\Users\me\anaconda3\envs\rpjax\include -IC:\Users\me\anaconda3\envs\rpjax\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.33.31629\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt" /EHsc /Tpriskparityportfolio/vanilla.cpp /Fobuild\temp.win-amd64-cpython-310\Release\riskparityportfolio/vanilla.obj /EHsc /DVERSION_INFO=\\\"0.3\\\"
      vanilla.cpp
      riskparityportfolio/vanilla.cpp(21): warning C4244: 'initializing': conversion from 'Eigen::EigenBase<Derived>::Index' to 'unsigned int', possible loss of data
              with
              [
                  Derived=Eigen::Matrix<double,-1,1,0,-1,1>
              ]
      riskparityportfolio/vanilla.cpp(21): warning C4244: 'initializing': conversion from 'Eigen::EigenBase<Derived>::Index' to 'const unsigned int', possible loss of data
              with
              [
                  Derived=Eigen::Matrix<double,-1,1,0,-1,1>
              ]
      riskparityportfolio/vanilla.cpp(50): warning C4244: 'initializing': conversion from 'Eigen::EigenBase<Derived>::Index' to 'unsigned int', possible loss of data
              with
              [
                  Derived=Eigen::Matrix<double,-1,1,0,-1,1>
              ]
      riskparityportfolio/vanilla.cpp(50): warning C4244: 'initializing': conversion from 'Eigen::EigenBase<Derived>::Index' to 'const unsigned int', possible loss of data
              with
              [
                  Derived=Eigen::Matrix<double,-1,1,0,-1,1>
              ]
      riskparityportfolio/vanilla.cpp(166): error C2017: illegal escape sequence
      riskparityportfolio/vanilla.cpp(166): error C2001: newline in constant
      riskparityportfolio/vanilla.cpp(170): error C2143: syntax error: missing ';' before '}'
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  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.
╰─> riskparityportfolio

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

Any advice on solving this? I suspect it is an error in the underlying C++ code in lines 166 & 167 of riskparityportfolio/vanilla.cpp, but I don't know enough C++ to handle it.

I had a fresh install of VS Build Tools today and also tried reinstalling this and restarting but alas to no avail.

mirca commented 1 year ago

@TheBounceBack would you mind sharing the output of:

import pybind11 as pb
import jaxlib
import jax

print((pb.__version__, jax.__version__, jaxlib.__version__))
ghost commented 1 year ago

Sure, I get: >>> print((pb.__version__, jax.__version__, jaxlib.__version__)) ('2.10.0', '0.2.22', '0.3.7')

mirca commented 1 year ago

hm, i see. would you mind try installing the development version?

git clone https://github.com/dppalomar/riskparity.py.git
cd riskparity.py
pip install -e .

PS: i'd love to be able to run CI on windows, but it seems jax is not yet officially supported on it.

ghost commented 1 year ago

Thanks. Unfortunately I seem to get the same error!

    riskparityportfolio/vanilla.cpp(167): error C2017: illegal escape sequence
    riskparityportfolio/vanilla.cpp(167): error C2001: newline in constant
    riskparityportfolio/vanilla.cpp(171): error C2143: syntax error: missing ';' before '}'
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
    [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
mirca commented 1 year ago
error C2143: syntax error: missing ';' before '}'

could you add a ";" after line 171 in vanilla.cpp and try again installing the dev version? maybe this is a windows thing because i can't reproduce your error on macos or ubuntu.

mirca commented 1 year ago

@TheBounceBack okay, i've pushed some changes to master that hopefully fixed this issue. could you try again:

git clone https://github.com/dppalomar/riskparity.py.git
cd riskparity.py
pip install -e .
ghost commented 1 year ago

I just tried again and this time a slightly different error. I think it might be something to do with Windows / linux line endings or spacing.

    vanilla.cpp
    riskparityportfolio/vanilla.cpp(170): error C2017: illegal escape sequence
    riskparityportfolio/vanilla.cpp(170): error C2001: newline in constant
    riskparityportfolio/vanilla.cpp(174): error C2143: syntax error: missing ';' before '}'
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
    [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
nankaimy commented 1 year ago

has the installation problem,win10,python 3.9

文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 riskparityportfolio/vanilla.cpp(21): warning C4244: “初始化”: 从“Eigen::EigenBase::Index”转换到“unsigned int”,可能丢失数据 with [ Derived=Eigen::Matrix<double,-1,1,0,-1,1> ] riskparityportfolio/vanilla.cpp(21): warning C4244: “初始化”: 从“Eigen::EigenBase::Index”转换到“const unsigned int”,可能丢失数据 with [ Derived=Eigen::Matrix<double,-1,1,0,-1,1> ] riskparityportfolio/vanilla.cpp(50): warning C4244: “初始化”: 从“Eigen::EigenBase::Index”转换到“unsigned int”,可能丢失数据 with [ Derived=Eigen::Matrix<double,-1,1,0,-1,1> ] riskparityportfolio/vanilla.cpp(50): warning C4244: “初始化”: 从“Eigen::EigenBase::Index”转换到“const unsigned int”,可能丢失数据 with [ Derived=Eigen::Matrix<double,-1,1,0,-1,1> ] riskparityportfolio/vanilla.cpp(166): error C2017: 非法的转义序列 riskparityportfolio/vanilla.cpp(166): error C2001: 常量中有换行符 riskparityportfolio/vanilla.cpp(170): error C2143: 语法错误: 缺少“;”(在“}”的前面) error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.33.31629\bin\HostX86\x64\cl.exe' failed with exit code 2

ERROR: Command errored out with exit status 1: 'C:\myprogram\Anaconda37\envs\py39\python.exe' -u -c 'import io, os, sys,

mirca commented 1 year ago

riskparityportfolio v0.4 now builds on windows. Thank you all for the discussions.