【发布时间】:2021-01-27 04:52:42
【问题描述】:
我在尝试使用 npm install -g <package-name> 安装的自定义 NPM 包遇到新问题。这个包有一个“安装后”步骤,运行pip install。要求适用于 Python 3 包,但 pip 安装失败,因为它在 Python 2 中运行:
> <package-name> postinstall /usr/local/lib/node_modules/<package-name>
> pip install --upgrade -r ./scripts/requirements.txt
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. [...removing for clarity...]
Defaulting to user installation because normal site-packages is not writeable
[...]
npm ERR! Failed at the <package-name>@<version> postinstall script.
我尝试在 Python 3 venv 环境中运行全局安装,并尝试使用 npm config set python python3.8 将 npm 指向 Python 3,基于 this question。似乎没有什么可以强制 postinstall 使用 Python 3 版本的 pip 运行,甚至没有直接指定 python 路径。
仅供参考:我的initial question 已关闭,因为它与上面链接的相似,但正如我所说,这对我没有帮助。另外,我在 macOS Mojave 上。
另外,当我在本地运行 npm run postinstall 时 - 在包的目录中 - 我得到了同样的错误。如果我只运行pip install 行,它就可以正常工作。在这里使用 npm run 会改变行为,但我不确定它是什么。
这是我公司维护的内部包。 pip install 行是唯一的安装后步骤。它安装了一系列要求,包括 matplotlib >= 3.0(因此需要 Python 3 - 这通常是它失败的地方)。我将pip install 更改为python -m pip install,实际上确实使用了正确的python 版本,然后在matplotlib 设置中失败。我认为这是关键。
【问题讨论】:
-
什么是包?
-
该包是我公司维护的内部包
-
那么我们无能为力,除非您可以分享正在使用 pip 的位的minimal reproducible example。
-
真的就是上面那一行,
pip install --upgrade -r ./scripts/requirements.txt。要求包括 matplotlib>=3.0,这是它失败的地方。我在帖子中添加了一些细节
标签: python macos npm installation pip