Read the Docs构建时安装somoclu出现numpy找不到错误
解决Read the Docs构建时somoclu找不到numpy的问题
问题原因
虽然全局环境已安装numpy,但pip构建somoclu这类需编译的包时,默认启用构建隔离机制——会在仅包含setuptools和wheel的临时环境中执行setup.py,这个临时环境里没有numpy,因此触发ModuleNotFoundError。
解决方案
1. 在requirements.txt中禁用构建隔离
直接在requirements.txt里添加参数,让pip在已安装numpy的当前环境中构建somoclu:
numpy==1.23.3 --no-build-isolation somoclu==1.7.5.1
注意将numpy放在参数前,确保它先完成安装。
2. 通过Read the Docs配置文件强制指定安装顺序
在项目根目录创建或修改.readthedocs.yaml,明确先安装numpy再安装somoclu:
build: os: ubuntu-22.04 tools: python: "3.9" python: install: - pip: - numpy==1.23.3 - somoclu==1.7.5.1 - requirements: docs/requirements.txt # 保留原有文档依赖的安装
这种方式能绕过构建隔离的限制,严格控制安装顺序。
3. 预安装numpy到构建环境
如果使用Read the Docs旧版配置文件(readthedocs.yml),可在构建前的步骤中先安装numpy:
build: pre_install: - pip install numpy==1.23.3
内容的提问来源于stack exchange,提问作者shinotakatoshi
相关产品推荐
相关产品推荐

