通过PIP安装NPM,但得到“npm:command not found”

时间:2016-06-27 20:04:40

标签: macos python-2.7 npm pip

我在OS X Yosemite 10.10.5上安装了Python 2.7。我想通过PIP安装NPM,命令显示成功,我在/Library/Python/2.7/site-packages/中有一个名为npm的目录,但是使用NPM执行任何操作会产生“找不到命令。”

这就是我安装PIP和NPM的方式:

第1步

sudo easy_install pip

将此作为输出:

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

第2步:

sudo -H pip install npm

将此作为输出:

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

第3步:

npm -v

将此作为输出:

-bash: npm: command not found

这是我的$ PATH变量中的内容,但为了便于阅读而分成单独的行。值得注意的是,我从其他人的机器上复制了这些,并且我的机器没有/ usr / local / lib目录。

/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

我对Linux并不陌生,但我是OS X的新手,所以这可能是我忽视的显而易见的事情。

3 个答案:

答案 0 :(得分:2)

如果您正在谈论npm(节点包管理器),您必须先安装Nodejs。 NPM附带Node。

要通过Mac执行此操作,请使用http://brew.shhttps://www.macports.org

brew update
brew install node

答案 1 :(得分:1)

您在第2步中执行的操作

sudo -H pip install npm 

不会在您的计算机上安装npm。 此命令仅要求安装名为npm 的python包。

包裹描述可用https://pypi.python.org/pypi/npm/0.1.1:)

如在developper github存储库中所描述的,这个python包是为“用于npm的Python绑定和工具”而设计的。

注意此套餐已取消资格。

如果你想安装npm,你应该检查node js web site

答案 2 :(得分:1)

对于 Python-3,要安装 npm(1) 命令(而不是 npm bindings),请执行以下操作:

${HOME}/pyvenv.d/ 成为 Python-3 虚拟环境所在的位置。然后:

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

只要 Python-3 虚拟环境保持激活状态,您现在就可以照常发出 npm(1) 命令。例如:

(pyvenv.d) user$ npm install [-g] configurable-http-proxy

我希望这会有所帮助。