安装tsfresh[matrixprofile]及matrixprofile包失败的技术求助
问题:tsfresh矩阵轮廓依赖安装失败及特征提取异常
- 使用最新版tsfresh做特征提取时,弹出警告「WARNING - Dependency not available for matrix_profile, this feature will be disabled!」并触发异常
- 创建Python 3.8版本的conda环境后,执行
pip install tsfresh[matrixprofile]时pip无法找到对应包 - 切换执行
pip install matrixprofile时出现元数据生成失败错误,更换不同版本的matrixprofile及Python版本后问题仍未解决
错误详情如下:
(tsfresh__py_3.8) alessio@Alessios-MBP Alessio % pip install matrixprofile Collecting matrixprofile Using cached matrixprofile-1.1.10.tar.gz (331 kB) Preparing metadata (setup.py) ... error error: subprocess-exited-with-error × python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [47 lines of output] /private/var/folders/s_/wcbhtkn953d2yl21zd8frrsr0000gn/T/pip-install-t8b6g2j3/matrixprofile_a5506b66a087426399cf87c5232c0f73/setup.py:4: _DeprecatedInstaller: setuptools.installer and fetch_build_eggs are deprecated. !! ******************************************************************************** Requirements should be satisfied by a PEP 517 installer. If you are using pip, you can try `pip install --use-pep517`. ******************************************************************************** !! dist.Distribution().fetch_build_eggs(['cython>=0.x', 'numpy>=1.16.2', 'wheel']) Traceback (most recent call last): File "/Users/alessio/miniforge3/envs/tsfresh__py_3.8/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 35, in __init__ parsed = _parse_requirement(requirement_string) File "/Users/alessio/miniforge3/envs/tsfresh__py_3.8/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 64, in parse_requirement return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES)) File "/Users/alessio/miniforge3/envs/tsfresh__py_3.8/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 82, in _parse_requirement url, specifier, marker = _parse_requirement_details(tokenizer) File "/Users/alessio/miniforge3/envs/tsfresh__py_3.8/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 126, in _parse_requirement_details marker = _parse_requirement_marker( File "/Users/alessio/miniforge3/envs/tsfresh__py_3.8/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 147, in _parse_requirement_marker tokenizer.raise_syntax_error( File "/Users/alessio/miniforge3/envs/tsfresh__py_3.8/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/_tokenizer.py", line 165, in raise_syntax_error raise ParserSyntaxError( pkg_resources.extern.packaging._tokenizer.ParserSyntaxError: Expected end or semicolon (after version specifier) cython>=0.x ~~~^ 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 "/private/var/folders/s_/wcbhtkn953d2yl21zd8frrsr0000gn/T/pip-install-t8b6g2j3/matrixprofile_a5506b66a087426399cf87c5232c0f73/setup.py", line 4, in <module> dist.Distribution().fetch_build_eggs(['cython>=0.x', 'numpy>=1.16.2', 'wheel']) File "/Users/alessio/miniforge3/envs/tsfresh__py_3.8/lib/python3.8/site-packages/setuptools/dist.py", line 907, in fetch_build_eggs return _fetch_build_eggs(self, requires) File "/Users/alessio/miniforge3/envs/tsfresh__py_3.8/lib/python3.8/site-packages/setuptools/installer.py", line 38, in _fetch_build_eggs resolved_dists = pkg_resources.working_set.resolve( File "/Users/alessio/miniforge3/envs/tsfresh__py_3.8/lib/python3.8/site-packages/pkg_resources/__init__.py", line 806, in resolve requirements = list(requirements)[::-1] File "/Users/alessio/miniforge3/envs/tsfresh__py_3.8/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3174, in __init__ super(Requirement, self).__init__(requirement_string) File "/Users/alessio/miniforge3/envs/tsfresh__py_3.8/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 37, in __init__ raise InvalidRequirement(str(e)) from e pkg_resources.extern.packaging.requirements.InvalidRequirement: Expected end or semicolon (after version specifier) cython>=0.x ~~~^ [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.
解决办法
1. 手动修复matrixprofile源码依赖
错误核心是matrixprofile的setup.py中使用了cython>=0.x这种不符合PEP规范的版本号,导致新版本pip/setuptools无法解析。按以下步骤操作:
- 先安装兼容的基础依赖:
pip install cython>=0.29.0 numpy>=1.16.2 wheel - 克隆matrixprofile源码:
git clone https://github.com/matrix-profile-foundation/matrixprofile.git - 进入源码目录,修改
setup.py第4行,将'cython>=0.x'替换为'cython>=0.29.0' - 执行本地安装:
pip install .
2. 禁用tsfresh的matrixprofile特征(无需该功能时使用)
如果不需要矩阵轮廓相关的特征,可以直接在特征提取时禁用该模块,避免触发异常:
from tsfresh import extract_features # 提取特征时跳过matrixprofile相关计算 features = extract_features( your_data, kind_to_fc_parameters={"matrix_profile": None} )
或者直接安装基础版tsfresh,不安装matrixprofile相关依赖:
pip install tsfresh
3. 尝试通过conda安装兼容版本
试试conda仓库中的预编译兼容版本:
conda install -c conda-forge matrixprofile
内容的提问来源于stack exchange,提问作者Alessio Bolpagni
相关产品推荐
相关产品推荐

