Reputation: 77
I have Python 2.7 installed on OS X Yosemite 10.10.5. I want to install NPM via PIP, and the command appears successful, and I have a directory named npm in /Library/Python/2.7/site-packages/, but doing anything with NPM yields "command not found."
This is how I installed PIP and NPM:
STEP 1
sudo easy_install pip
gave this as output:
Reading https://pypi.python.org/simple/pip/
Best match: pip 8.1.2
Downloading https://pypi.python.org/packages/e7/a8/7556133689add8d1a54c0b14aeff0acb03c64707ce100ecd53934da1aa13/pip-8.1.2.tar.gz#md5=87083c0b9867963b29f7aba3613e8f4a
Processing pip-8.1.2.tar.gz
Writing /tmp/easy_install-v4g_ZO/pip-8.1.2/setup.cfg
Running pip-8.1.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-v4g_ZO/pip-8.1.2/egg-dist-tmp-5Ku7Ds
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching '.landscape.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
warning: no previously-included files found matching 'appveyor.yml'
no previously-included directories found matching '.github'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
Adding pip 8.1.2 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
STEP 2:
sudo -H pip install npm
gave this as output:
Collecting npm
Using cached npm-0.1.1.tar.gz
Requirement already satisfied (use --upgrade to upgrade): optional-django==0.1.0 in /Library/Python/2.7/site-packages (from npm)
Installing collected packages: npm
Running setup.py install for npm ... done
STEP 3:
npm -v
gave this as output:
-bash: npm: command not found
Here is what is in my $PATH variable, but broken into separate lines for ease of reading. Of note is that I copied these from someone else's machine, and that my machine does not have the /usr/local/lib directory.
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/opt/local/bin:
/opt/local/sbin:
/usr/local/lib/python2.7:
/usr/local/lib/python2.7/site-packages:
/usr/local/lib/node_modules:
/usr/bin/python2.7:
/Library/Python/2.7/site-packages/npm
I'm no stranger to Linux, but I'm new to OS X, so this could be something obvious I'm overlooking.
Upvotes: 4
Views: 25107
Reputation: 5689
For Python-3
, to install the npm(1)
command (not npm bindings
), this is what to do:
Let ${HOME}/pyvenv.d/
be where the Python-3
virtual environment exists. Then:
user$ source ${HOME}/pyvenv.d/activate
(pyvenv.d) user$ pip install nodeenv # Install a tool that can install a pre-build npm(1) version.
(pyvenv.d) user$ nodeenv -p # Run tool to install npm(1) in current Python venv.
(pyvenv.d) user$ which npm
/home/user/pyvenv.d/bin/npm
(pyvenv.d) user$ npm --version
7.3.0
(pyvenv.d) user$ which node
/home/user/pyvenv.d/bin/node
(pyvenv.d) user$ node --version
v15.5.0
As long as the Python-3
virtual environment remains activated, you can now issue npm(1)
commands as normal. For example:
(pyvenv.d) user$ npm install [-g] configurable-http-proxy
I hope this helps.
Upvotes: 3
Reputation: 31
If you are talking about npm (Node Package Manager) you have to install Nodejs first. NPM comes with Node.
To do this via Mac, use http://brew.sh or https://www.macports.org.
brew update
brew install node
Upvotes: 3
Reputation: 96
the operation you did in step 2
sudo -H pip install npm
does not install npm on your computer. This command only ask for installing a python package named npm.
The package description is available https://pypi.python.org/pypi/npm/0.1.1 : )
as described on the developper github repository, this python package is designed for "Python bindings and utils for npm".
note This package is UNMAINTAINED.
if you want to install npm you should check the node js web site
Upvotes: 8