You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法安装pyfolio:多尝试途径均失败的技术求助

pyfolio安装失败:AttributeError: module 'configparser' has no attribute 'SafeConfigParser'

错误信息

执行pip install pyfolio时触发以下错误:

C:\WINDOWS\system32>pip install pyfolio
Collecting pyfolio
  Using cached pyfolio-0.9.2.tar.gz (91 kB)
  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]
      C:\Users\Winod Dhamnekar\AppData\Local\Temp\pip-install-p7nv43_t\pyfolio_14ad331ba5cf4f91ac9cb9e3470e3bf8\versioneer.py:468: SyntaxWarning: invalid escape sequence '\s'
        LONG_VERSION_PY['git'] = '''
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\Winod Dhamnekar\AppData\Local\Temp\pip-install-p7nv43_t\pyfolio_14ad331ba5cf4f91ac9cb9e3470e3bf8\setup.py", line 71, in <module>
          version=versioneer.get_version(),
                  ^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\Winod Dhamnekar\AppData\Local\Temp\pip-install-p7nv43_t\pyfolio_14ad331ba5cf4f91ac9cb9e3470e3bf8\versioneer.py", line 1407, in get_version
          return get_versions()["version"]
                 ^^^^^^^^^^^^^^
        File "C:\Users\Winod Dhamnekar\AppData\Local\Temp\pip-install-p7nv43_t\pyfolio_14ad331ba5cf4f91ac9cb9e3470e3bf8\versioneer.py", line 1341, in get_versions
          cfg = get_config_from_root(root)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\Winod Dhamnekar\AppData\Local\Temp\pip-install-p7nv43_t\pyfolio_14ad331ba5cf4f91ac9cb9e3470e3bf8\versioneer.py", line 399, in get_config_from_root
          parser = configparser.SafeConfigParser()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      AttributeError: module 'configparser' has no attribute 'SafeConfigParser'. Did you mean: 'RawConfigParser'?
      [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.

C:\WINDOWS\system32>

已尝试但无效的操作

  • 切换到Python 3.8、3.6旧环境安装
  • 下载pyfolio 0.9.2压缩包,修改versioneer.py里的SafeConfigParser为ConfigParser后安装
  • 用管理员权限执行conda install -c conda-forge pyfolio安装

解决办法

1. 安装维护分支版本(推荐)

官方的pyfolio 0.9.2已经停更很久,兼容性问题较多,直接安装quantopian仓库的master分支即可:

pip install git+https://github.com/quantopian/pyfolio.git@master

2. 修复本地包的两处问题(适合非要装0.9.2的情况)

之前仅修改了一处,还遗漏了转义序列错误,需修改两个地方:

  • 在versioneer.py第399行,将configparser.SafeConfigParser()改为configparser.ConfigParser()
  • 在versioneer.py第468行,给字符串开头加上r(改为原始字符串),即LONG_VERSION_PY['git'] = r''',解决\s转义错误

修改完成后进入解压后的文件夹,执行:

pip install .

3. 用Docker容器规避环境问题

不想折腾本地环境的话,可选用包含pyfolio的量化分析Docker镜像(比如基于Python 3.7的镜像),直接在容器内使用pyfolio。


内容的提问来源于stack exchange,提问作者Winodd Dhamnekar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 03:02:37