我在OS X Yosemite 10.10.5上安装了Python 2.7。我想通过PIP安装NPM,并且命令显示成功,并且我在/Library/Python/2.7/site-packages/中有一个名为NPM的目录,但是对NPM进行任何操作都会产生"command not found"。
我是这样安装PIP和NPM的:
步骤1sudo 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的新手,所以这可能是我忽视的一些明显的东西。
您在第2步中执行的操作
sudo -H pip install npm
没有在您的计算机上安装NPM。这个命令只要求安装一个名为npm的python包。
软件包描述可用https://pypi.python.org/pypi/npm/0.1.1:)
正如developer github存储库中描述的那样,这个python包是为"python绑定和npm的utils"设计的。
这个包是unmaintenance .
如果你想安装NPM,你应该检查节点js的网站
如果你说的是npm (Node Package Manager),你必须先安装Nodejs。NPM是Node自带的。
要通过Mac执行此操作,请使用http://brew.sh或https://www.macports.org。
brew update
brew install node
对于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