0

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.

mercer721
  • 103
  • 1
  • 9

1 Answers1

0

You tried this commands:

  echo "alias python=/usr/local/bin/python3.7" >> ~/.zshrc
  echo "alias python=/usr/local/bin/python3.7" >> ~/.bashrc

Or use brew?

  brew update && brew upgrade python

Put this alias on you .rc file if you dont have:

  alias python=/usr/local/bin/python3

See this page they have a lot of tricks: https://opensource.com/article/19/5/python-3-default-mac

Maurilio Atila
  • 146
  • 2
  • 6
  • I tried adding aliases to ~/.bashrc and it didn't work. I use brew, and I ran `brew update && brew upgrade python` yesterday. The package is an internal package maintained by my company – mercer721 Oct 12 '20 at 21:31
  • You tried change the command to pip3 -> `pip3 install --upgrade -r ./scripts/requirements.txt`? – Maurilio Atila Oct 12 '20 at 23:15
  • No, I don't want to do that since it won't be supported by all machines – mercer721 Oct 13 '20 at 13:34