2013-02-28 19 views
140

我正在進入一個Node.js代碼庫,它要求我通過NPM(即jQuery)下載一些依賴項。在Windows上爲Node.js依賴項運行Python

在試圖運行npm install jquery,我不斷收到此錯誤:

Your environment has been set up for using Node.js 0.8.21 (x64) and NPM 

C:\Users\Matt Cashatt>npm install jquery 
npm http GET https://registry.npmjs.org/jquery 
npm http 304 https://registry.npmjs.org/jquery 
npm http GET https://registry.npmjs.org/jsdom 
npm http GET https://registry.npmjs.org/xmlhttprequest 
npm http GET https://registry.npmjs.org/htmlparser/1.7.6 
npm http GET https://registry.npmjs.org/location/0.0.1 
npm http GET https://registry.npmjs.org/navigator 
npm http GET https://registry.npmjs.org/contextify 
npm http 304 https://registry.npmjs.org/htmlparser/1.7.6 
npm http 304 https://registry.npmjs.org/xmlhttprequest 
npm http 304 https://registry.npmjs.org/location/0.0.1 
npm http 304 https://registry.npmjs.org/navigator 
npm http 304 https://registry.npmjs.org/jsdom 
npm http 304 https://registry.npmjs.org/contextify 
npm http GET https://registry.npmjs.org/bindings 
npm http GET https://registry.npmjs.org/cssom 
npm http GET https://registry.npmjs.org/cssstyle 
npm http GET https://registry.npmjs.org/request 
npm http 304 https://registry.npmjs.org/bindings 

> [email protected] install C:\Users\Matt Cashatt\node_modules\jquery\node_module 
s\contextify 
> node-gyp rebuild 


C:\Users\Matt Cashatt\node_modules\jquery\node_modules\contextify>node "C:\Progr 
am Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\b 
in\node-gyp.js" rebuild 
npm http 304 https://registry.npmjs.org/cssstyle 
npm http 304 https://registry.npmjs.org/cssom 
npm http 304 https://registry.npmjs.org/request 
gyp ERR! configure error 
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT 
HON env variable. 
gyp ERR! stack  at failNoPython (C:\Program Files\nodejs\node_modules\npm\nod 
e_modules\node-gyp\lib\configure.js:113:14) 
gyp ERR! stack  at C:\Program Files\nodejs\node_modules\npm\node_modules\node 
-gyp\lib\configure.js:82:11 
gyp ERR! stack  at Object.oncomplete (fs.js:297:15) 
gyp ERR! System Windows_NT 6.1.7601 
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modu 
les\\node-gyp\\bin\\node-gyp.js" "rebuild" 
gyp ERR! cwd C:\Users\Matt Cashatt\node_modules\jquery\node_modules\contextify 
gyp ERR! node -v v0.8.21 
gyp ERR! node-gyp -v v0.8.4 
gyp ERR! not ok 
npm ERR! error rolling back Error: ENOTEMPTY, rmdir 'C:\Users\Matt Cashatt\node_ 
modules\jquery\node_modules\jsdom\node_modules\request\tests' 
npm ERR! error rolling back [email protected] { [Error: ENOTEMPTY, rmdir 'C:\Users\M 
att Cashatt\node_modules\jquery\node_modules\jsdom\node_modules\request\tests'] 
npm ERR! error rolling back errno: 53, 
npm ERR! error rolling back code: 'ENOTEMPTY', 
npm ERR! error rolling back path: 'C:\\Users\\Matt Cashatt\\node_modules\\jque 
ry\\node_modules\\jsdom\\node_modules\\request\\tests' } 
npm ERR! [email protected] install: `node-gyp rebuild` 
npm ERR! `cmd "/c" "node-gyp rebuild"` failed with 1 
npm ERR! 
npm ERR! Failed at the [email protected] install script. 
npm ERR! This is most likely a problem with the contextify package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  node-gyp rebuild 
npm ERR! You can get their info via: 
npm ERR!  npm owner ls contextify 
npm ERR! There is likely additional logging output above. 

npm ERR! System Windows_NT 6.1.7601 
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod 
ejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "jquery" 
npm ERR! cwd C:\Users\Matt Cashatt 
npm ERR! node -v v0.8.21 
npm ERR! npm -v 1.2.11 
npm ERR! code ELIFECYCLE 
npm ERR! Error: ENOENT, lstat 'C:\Users\Matt Cashatt\node_modules\jquery\node_mo 
dules\jsdom\node_modules\request\tests\test-pipes.js' 
npm ERR! If you need help, you may report this log at: 
npm ERR!  <http://github.com/isaacs/npm/issues> 
npm ERR! or email it to: 
npm ERR!  <[email protected]> 

npm ERR! System Windows_NT 6.1.7601 
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod 
ejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "jquery" 
npm ERR! cwd C:\Users\Matt Cashatt 
npm ERR! node -v v0.8.21 
npm ERR! npm -v 1.2.11 
npm ERR! path C:\Users\Matt Cashatt\node_modules\jquery\node_modules\jsdom\node_ 
modules\request\tests\test-pipes.js 
npm ERR! fstream_path C:\Users\Matt Cashatt\node_modules\jquery\node_modules\jsd 
om\node_modules\request\tests\test-pipes.js 
npm ERR! fstream_type File 
npm ERR! fstream_class FileWriter 
npm ERR! code ENOENT 
npm ERR! errno 34 
npm ERR! fstream_stack C:\Program Files\nodejs\node_modules\npm\node_modules\fst 
ream\lib\writer.js:284:26 
npm ERR! fstream_stack Object.oncomplete (fs.js:297:15) 
npm ERR! 
npm ERR! Additional logging details can be found in: 
npm ERR!  C:\Users\Matt Cashatt\npm-debug.log 
npm ERR! not ok code 0 

C:\Users\Matt Cashatt> 

它看起來像失敗是由於缺少Python安裝。那麼,我已經安裝了Python,設置了變量,並重新啓動了,仍然是錯誤。

任何線索,我失蹤了什麼?

+0

可以粘貼文本,文本,而不是圖像?除了難以閱讀(尤其是因爲它顯然縮小了已經低分辨率的位圖字體),它不可複製。 – abarnert 2013-02-28 01:55:05

+1

更重要的是:您在重新啓動之前如何設置環境變量?如果您在cmd窗口中執行了'PYTHON = C:\ Python27 \ Python.exe'並重新啓動,則設置丟失。 – abarnert 2013-02-28 01:56:28

+6

另外,你安裝了哪個Python版本?至少老版本的waf和gyp需要2.x,但是沒有提及任何關於它的內容,如果你安裝了3.x,會給出各種神祕的錯誤。 – abarnert 2013-02-28 01:57:35

回答

92

你的問題是你的沒有設置環境變量

這個錯誤清楚地這樣說:

gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable. 

而在你的評論,你說你這樣做:

set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib 

這很好,但沒有設置PYTHON變量,它集變量爲PYTHONPATH


同時,只使用set命令隻影響當前cmd會議。如果您在此之後重新啓動,就像您說的那樣,您將得到一個全新的cmd會話,該會話中沒有設置該變量。

有幾種方法永久設置環境變量 - 最簡單的是在XP系統控制面板中,這在Vista中當然是不同的,在7中又不同了,而在8中又是不同的,但是您可以通過谷歌它。

或者,只需在npm命令之前執行set,而不必在兩者之間重新啓動。


您可以測試是否做了正確的事情做的配置腳本試圖做同樣的事情:在運行npm之前,嘗試運行%PYTHON%。如果你做得對,你會得到一個Python解釋器(你可以立即退出)。如果你得到一個錯誤,你沒有做對。


有兩個問題:

set PYTHON=%PYTHON%;D:\Python 

首先,你設置PYTHON;D:\Python。對於以分號分隔的路徑列表來說,額外的分號很合適,如PATHPYTHONPATH,但不適用於像PYTHON這樣的單個值。同樣,爲現有值添加一個新值是您希望將另一個路徑添加到路徑列表時的值,但不是針對單個值。所以,你只需要set PYTHON=D:\Python

其次,D:\Python不是Python解釋器的路徑。這就像D:\Python\Python.exeD:\Python\bin\Python.exe。找到正確的道路,確保它能夠獨立運作(例如,,輸入D:\Python\bin\Python.exe並確保你得到一個Python解釋器),然後設置變量並使用它。


所以:

set PYTHON=D:\Python\bin\Python.exe 

或者,如果你想讓它永久,執行控制面板中的等價物。

+1

好的,所以我得到這個:Microsoft Windows [Version 6.1.7601] Copyright(c)2009 Microsoft Corporation。版權所有。 C:\用戶\馬特Cashatt>設置PYTHON =%PYTHON%; d:\的Python C:\用戶\馬特Cashatt>%PYTHON% '%PYTHON%' 不被識別爲一個內部或外部的命令, 可操作的程序或批處理文件。 C:\ Users \ Matt Cashatt> – 2013-02-28 02:05:56

+0

抱歉格式化。 – 2013-02-28 02:06:20

+1

此外,'D'驅動器是我在Python中的情況下,你想知道。再次感謝你的幫助。 – 2013-02-28 02:07:00

4

我有同樣的問題,這些答案都沒有幫助。 在我的情況下,PYTHON變量設置正確。然而python安裝的太深,也就是路徑太長。所以,我做了以下:

  1. 重新安裝蟒蛇到c:\ python的
  2. 設置環境變量PYTHON到C:\ python的\ python.exe

就是這樣!

3

TL; DR使您的python.exe的副本或別名名稱爲python2.7.exe

我的Python 2.7安裝爲

D:\app\Python27\python.exe

我總是得到這個錯誤無論怎樣我一套(及驗證)PYTHON環境變量:

 
gyp ERR! stack Error: Can't find Python executable "python2.7", you can set the PYTHON env variable. 
gyp ERR! stack  at failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:103:14) 

這樣做的原因是,在節點GYP的configure.js python的可執行文件得到解決,如:

var python = gyp.opts.python || process.env.PYTHON || 'python'

而且事實證明,gyp.opts.python有值 'python2.7' 超然process.env.PYTHON。

我解決了這個通過創建名稱爲節點GYP python.exe可執行的別名正在尋找:

D:\app\Python27>mklink python2.7.exe python.exe

您需要進行此操作管理員權限。

0

下面是正確的命令:設置path =%PATH%; C:\ Python34

我有同樣的問題,我只是解決了這個像[用你的Python安裝的正確路徑替換。

正如其他人指出的那樣,這是易失性配置,它只適用於當前的cmd會話,並且(顯然)必須在運行npm install之前設置路徑。

我希望這會有所幫助。

0

gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT HON env variable.

沒有必要重新安裝,這個異常拋出node-gyp腳本,然後嘗試重建。這足以設置環境變量,就像我的情況下,我做的事:

SET PYTHON=C:\work\_env\Python27\python.exe 
0

如果你想使用這個在Cygwin,那麼你就需要按照this答案的說明。 (這是一個問題的Cygwin如何將Windows符號鏈接。)

4

一個和/或這些的倍數應該幫助:

  1. 添加C:\Python27\PATH變量(考慮您已經安裝了此目錄中的Python)
    如何設置PATH env變量:http://www.computerhope.com/issues/ch000549.htm
    設置變量後重新啓動控制檯和/或Windows。

  2. 在同一節上文(「環境變量」),增加新的變量,名稱PYTHON和值C:\Python27\python.exe
    設置變量後 重新啓動控制檯和/或Windows。

  3. 以管理模式打開Windows命令行(cmd
    改變目錄到你的Python安裝路徑爲:需要一些安裝cd C:\Python27
    製作符號鏈接:mklink python2.7.exe python.exe

請注意,你應該有Python的2.X,NOT 3.x中,基於運行node-gyp安裝!

下面的文本表示有關Unix,但Windows版本還需要Python 2.x的:

You can install with npm: 

$ npm install -g node-gyp 
You will also need to install: 

On Unix: 
python (v2.7 recommended, v3.x.x is not supported) 
make 
A proper C/C++ compiler toolchain, like GCC 

本文還可以幫助:https://github.com/nodejs/node-gyp#installation

230

如果你沒有得到所有一起安裝的Python節點-GYP依賴條件,只需執行:

npm install --global --production windows-build-tools 

,然後安裝的軟件包:

npm install --global node-gyp 

安裝完成後,將會下載所有node-gyp依賴項,但仍需要環境變量。驗證Python,在正確的文件夾確實發現:

C:\Users\ben\.windows-build-tools\python27\python.exe 

Note - it uses python 2.7 not 3.x as it is not supported

如果沒有呻吟,繼續創建您的(用戶)環境變量:

setx PYTHON "%USERPROFILE%\.windows-build-tools\python27\python.exe" 

重啓CMD ,並通過set PYTHON驗證變量存在,該變量應返回變量

最後重新應用npm install <module>

+0

我有一些權限錯誤,但設法手動安裝python: C:\ Users \ [me] \。windows-build-tools \ python.msi。 在安裝中是一個將其添加到路徑的選項。 (重新啓動cmd/PS),它工作 – 2017-08-12 09:46:35

+0

我得到的錯誤dh鍵太小:openssk \ ssl \ s3_clnt,c:3641 – user1428716 2017-09-13 06:58:21

+7

需要安裝windows-build-tools PowerShell在Windows 10上以Admin身份運行。這意味着setx命令成爲'setx PYTHON $ env:USERPROFILE \ .windows-build-tools \ python27 \ python.exe' – Bae 2017-10-30 23:43:14

1

爲什麼不下載python安裝程序here?它使你的工作,當你檢查路徑安裝

0

以下爲我工作在命令行管理員:

安裝Windows建造工具(這可能需要15-20分鐘):

npm --add-python-to-path='true' --debug install --global windows-build-tools 

添加/更新所述環境變量:

setx PYTHON "%USERPROFILE%\.windows-build-tools\python27\python.exe" 

安裝節點-GYP:

npm install --global node-gyp 

將Python文件的名稱從Python更改爲Python2.7。

C:\Users\username\.windows-build-tools\python27\Python2.7 

npm install module_name --save

0

有一些解決方案來解決這個問題: 1)運行命令提示符爲 「管理員」。

如果第一個解決方案無法解決您的問題,試試這個:

2)打開命令提示符以管理員身份粘貼下面的代碼行並回車:

npm install --global --production windows-build-tools