每当我安装某些node
包时,都会出现涉及Python
版本的错误。这是因为我同时拥有Python 2.7
和Python 3.3
(我上次更新的时候是最新版本,现在是3.4
),但显然我只能在我的 PATH
中获取一个版本(任何后来的文件夹都被覆盖)。我的 PATH
中有 Python 3.3
因为它较新,但是仍然有很多程序,包括 npm
模块,它们使用 Python 2
,5 年多后。
对于还不能使用版本 3 的模块,有什么方法可以包含一个“后备”Python
版本吗?一个通用的解决方案会很棒,但我至少想要一个用于安装 npm
模块的解决方案。请记住,某些模块可能完全适用于 Python 3
,但我不确定是否有任何模块不能使用 Python 2
。话虽如此,最好的解决方案是同时允许在兼容时使用最新版本,在不兼容时使用旧版本。
作为引用,我的 Python 2.7
安装在 C:\Python27\python
文件夹中,Python 3.3
安装在 C:\Python33\python
文件夹。我得到的 npm
错误是:
contextify@0.1.8 install c:\repos\konneka\node_modules\buster\node_modules\bus ter-syntax\node_modules\jsdom\node_modules\contextify node-gyp rebuild
|
c:\repos\konneka\node_modules\buster\node_modules\buster-syntax\node_modules\jsd
om\node_modules\contextify>node "c:\Program Files\nodejs\node_modules\npm\bin\no
de-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
when@1.3.0 node_modules\buster\node_modules\buster-server-cli\node_modules\buste
r-cli\node_modules\buster-configuration\node_modules\when
lodash@0.5.2 node_modules\buster\node_modules\buster-test-cli\node_modules\ramp\
node_modules\ramp-resources\node_modules\lodash
gyp ERR! configure error
gyp ERR! stack Error: Python executable "python" is v3.3.2, which is not support
ed by gyp.
gyp ERR! stack You can pass the --python switch to point to Python >= v2.5.0 & <
3.0.0.
gyp ERR! stack at failPythonVersion (c:\Program Files\nodejs\node_modules\np
m\node_modules\node-gyp\lib\configure.js:108:14)
gyp ERR! stack at c:\Program Files\nodejs\node_modules\npm\node_modules\node
-gyp\lib\configure.js:97:9
gyp ERR! stack at ChildProcess.exithandler (child_process.js:645:7)
gyp ERR! stack at ChildProcess.emit (events.js:98:17)
gyp ERR! stack at maybeClose (child_process.js:755:16)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:822:
5)
ERR! System Windows_NT 6.2.9200
command "node" "c:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\nod
e-gyp\\bin\\node-gyp.js" "rebuild"
esprima-fb@3001.1.0-dev-harmony-fb node_modules\browserify\node_modules\syntax-e
rror\node_modules\esprima-fb
http-proxy@0.10.4 node_modules\karma\node_modules\http-proxy
├── pkginfo@0.3.0
└── utile@0.2.1 (deep-equal@0.2.1, async@0.2.10, ncp@0.4.2, i@0.3.2, mkdirp@0.5.
0)
cwd c:\repos\konneka\node_modules\buster\node_modules\buster-syntax\node_module
s\jsdom\node_modules\contextify
gyp ERR! node -v v0.10.29
gyp ERR! node-gyp -v v0.13.1
gyp ERR! not ok
最佳答案
使用virtualenv和 nodeenv并拥有您想要的任何版本组合。
关于python - npm 使用 2 个版本的 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24742455/