我在OS X Yosemite 10.10.5上安装了Python 2.7。我想通过PIP安装NPM,并且命令显示成功,并且我在/Library/Python/2.7/site-packages/中有一个名为npm的目录,但是对NPM执行任何操作都会产生“没有找到命令”。
下面是我安装PIP和NPM的方式:
第一步
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的新手,所以这可能是我明显忽略的事情。
发布于 2016-10-26 05:17:42
您在步骤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
发布于 2016-10-26 06:11:34
如果您正在谈论npm (Node Package Manager),您必须首先安装Nodejs。NPM自带Node。
要通过Mac执行此操作,请使用http://brew.sh或https://www.macports.org。
brew update
brew install node
发布于 2020-12-24 04:06:10
对于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
我希望这能帮到你。
https://stackoverflow.com/questions/38062328
复制相似问题