I'm having a new issue with a custom NPM package I'm trying to install with npm install -g <package-name>
. This package has a "postinstall" step, which runs pip install
. The requirements are for Python 3 packages, but the pip install fails because it runs in 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.
I've tried running the global installation in a Python 3 venv environment, and I tried pointing npm to Python 3 with npm config set python python3.8
, based on this question. Nothing seems to force the postinstall to run with a Python 3 version of pip, not even specifying the python path directly.
FYI: My initial question was closed because of its similarity to the one linked above, but as I said, that didn't help me. Also, I'm on macOS Mojave.
Also, when I run npm run postinstall
locally - in the directory of the package - I get the same error. If I just run the pip install
line, it works fine. There's something about using npm run
here that changes the behavior, but I'm not sure what it is.
This is an internal package maintained by my company. The pip install line is the only postinstall step. It installs a list of requirements including matplotlib >= 3.0 (so Python 3 is required - this is usually where it fails). I changed pip install
to python -m pip install
, which actually did use the right python version, then failed in the matplotlib setup. I think that's the key.