Poetry无法升级Polars至0.15.16的技术求助
问题:Poetry更新Polars至0.15.16失败,提示需Rust/Cargo
我维护一个以Python和Polars为主的代码仓库,每次用Poetry更新或添加依赖都会触发错误。Polars 0.15.15及之前版本使用完全正常,试过通过PyCharm IDE和Brew更新Polars,问题仍未解决。想了解这是Polars新版本的问题,还是Mac M1系统的问题?
错误详情
Package operations: 0 installs, 1 update, 0 removals • Updating polars (0.15.15 -> 0.15.16): Failed CalledProcessError Command '['/Users/PATH/.venv/bin/python', '-m', 'pip', 'install', '--use-pep517', '--disable-pip-version-check', '--isolated', '--no-input', '--prefix', '/Users/PATH/.venv', '--upgrade', '--no-deps', '/Users/PATH/Library/Caches/pypoetry/artifacts/58/97/2d/cb5f20eacd75bb88a57321c5a81a2b591330ccb0ae2fc786fffbe500eb/polars-0.15.16.tar.gz']' returned non-zero exit status 1. at /opt/homebrew/Cellar/python@3.11/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py:571 in run 567│ # We don't call process.wait() as .__exit__ does that for us. 568│ raise 569│ retcode = process.poll() 570│ if check and retcode: → 571│ raise CalledProcessError(retcode, process.args, 572│ output=stdout, stderr=stderr) 573│ return CompletedProcess(process.args, retcode, stdout, stderr) 574│ 575│ The following error occurred when trying to handle this error: EnvCommandError Command ['/Users/PATH/.venv/bin/python', '-m', 'pip', 'install', '--use-pep517', '--disable-pip-version-check', '--isolated', '--no-input', '--prefix', '/Users/PATH/.venv', '--upgrade', '--no-deps', '/Users/PATH/Library/Caches/pypoetry/artifacts/58/97/2d/cb5f20eacd75bb88a57321c5a81a2b591330ccb0ae2fc786fffbe500eb/polars-0.15.16.tar.gz'] errored with the following return code 1, and output: Processing /Users/PATH/Library/Caches/pypoetry/artifacts/58/97/2d/cb5f20eacd75bb88a57321c5a81a2b591330ccb0ae2fc786fffbe500eb/polars-0.15.16.tar.gz 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' Preparing metadata (pyproject.toml): started Preparing metadata (pyproject.toml): finished with status 'error' error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [6 lines of output] Cargo, the Rust package manager, is not installed or is not on PATH. This package requires Rust and Cargo to compile extensions. Install it through the system's package manager or via https://rustup.rs/ Checking for Rust toolchain.... [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. at /opt/homebrew/Cellar/poetry/1.3.2/libexec/lib/python3.11/site-packages/poetry/utils/env.py:1540 in _run 1536│ output = subprocess.check_output( 1537│ command, stderr=subprocess.STDOUT, env=env, **kwargs 1538│ ) 1539│ except CalledProcessError as e: → 1540│ raise EnvCommandError(e, input=input_) 1541│ 1542│ return decode(output) 1543│ 1544│ def execute(self, bin: str, *args: str, **kwargs: Any) -> int: The following error occurred when trying to handle this error: PoetryException Failed to install /Users/PATH/Library/Caches/pypoetry/artifacts/58/97/2d/cb5f20eacd75bb88a57321c5a81a2b591330ccb0ae2fc786fffbe500eb/polars-0.15.16.tar.gz at /opt/homebrew/Cellar/poetry/1.3.2/libexec/lib/python3.11/site-packages/poetry/utils/pip.py:58 in pip_install 54│ 55│ try: 56│ return environment.run_pip(*args) 57│ except EnvCommandError as e: → 58│ raise PoetryException(f"Failed to install {path.as_posix()}") from e 59│
原因分析
错误日志里的核心提示Cargo, the Rust package manager, is not installed or is not on PATH明确指出:Polars 0.15.16版本在你的M1环境中没有可用的预编译二进制包,导致Poetry尝试从源码编译Polars,而编译需要Rust的包管理工具Cargo。这既不是M1系统本身的问题,也不是Polars新版本的bug,而是依赖安装时的编译环境缺失。
解决办法
方案1:安装Rust/Cargo
在Mac M1上通过Brew安装:
brew install rustup-init rustup-init
安装完成后重启终端,验证cargo命令可正常执行,再运行Poetry更新:
poetry update polars
方案2:强制使用预编译二进制包
若不想安装Rust,可指定pip优先拉取wheel包:
poetry run pip install --only-binary :all: polars==0.15.16
之后同步Poetry依赖:
poetry lock --no-update poetry install
内容的提问来源于stack exchange,提问作者Horseman
相关产品推荐
相关产品推荐

