27

I am trying to set an older version of python in order to install modules and build an old node project.

I run this command:

npm config set python=python2.7

OR

npm config set python C:\Python27\python.exe

In both cases I am getting this error:

npm ERR! `python` is not a valid npm option 

Nove v16.14.2

Npm v9.1.2

1
  • I faced the same problem trying to set user option, that worked with 8.14 Commented Nov 30, 2022 at 6:45

4 Answers 4

42

Consider downgrading npm to v8 for now:

npm install -g npm@^8

Alternatively, just run:

npm config edit

and add:

python=C:\Python27\python.exe

in a new line.

Sign up to request clarification or add additional context in comments.

4 Comments

I didn't need to downgrade npm, but editing the config directly helped solve my issue indeed. Still curious why npm config set didn't work though. Thanks!
On my Mac I needed to add following to the config: python=/usr/bin/python3
Can someone explain why a downgrade is needed? Is there a different syntax necessary for later versions of NPM?
@StingyJack A downgrade is not needed. You can edit your config manually or maybe also pass the --python arg to install command. Also, newer versions of node-gyp have different recommendations - github.com/nodejs/node-gyp#configuring-python-dependency (you can set npm_config_python or PYTHON env variable).
0

Running Raspberry Pi node v20.18.2 code on my Ubuntu 22.04 I was able to install with the following:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
npm install --python=/usr/bin/python

I didn't go back and update my python back to 3.10.12 since I run python with "python3" instead of "python".

Comments

-1

Update your npm

npm install -g npm@^8

Retry the command

npm config set python C:\Python27\python.exe

Comments

-3

Consider running fix command:

npm config fix

In my case, it resolved the issue

1 Comment

Even if the config file was broken, fixing it could not possibly make npm understand an unsupported command. Either you switched to an older version of npm, or you had a different issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.