trysis
trysis

Reputation: 8416

npm Use 2 Versions of Python

Whenever I install certain node packages, there are errors involving the Python version. This is because I have both Python 2.7 and Python 3.3 (those were the latest versions last time I updated, but now there is 3.4), but obviously I can only source one version in my PATH (any later folders are overridden). I have Python 3.3 in my PATH because it's newer, but there are still so many programs, including npm modules, which use Python 2, over 5 years later.

Is there any way to include a "fallback" Python version, for modules which can not use version 3 yet? A general solution would be amazing, but I would at least like a solution for when installing npm modules. Keep in mind that some modules may be perfectly fine with Python 3, though I'm not sure if there are any which can not use Python 2. With that said, a solution which allows both, using the newest version when compatible and some older version when not, would be best.

For reference, my Python 2.7 is installed in the C:\Python27\python folder and Python 3.3 is in the C:\Python33\python folder. The npm error I am getting is:

[email protected] 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
[email protected] node_modules\buster\node_modules\buster-server-cli\node_modules\buste
r-cli\node_modules\buster-configuration\node_modules\when
[email protected] 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"
[email protected] node_modules\browserify\node_modules\syntax-e
rror\node_modules\esprima-fb
[email protected] node_modules\karma\node_modules\http-proxy
├── [email protected]
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected].
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

Upvotes: 6

Views: 4135

Answers (2)

James Kent
James Kent

Reputation: 5933

the way i flip between them is using the shebang at the beginning of python files

by including:

#!python2

at the beginning of the file, when you double click it the py.exe (or pyw.exe) passes it to that version of python (assuming it can find it) you can even pass it:

#!python2.7

to explicitly use version 2.7 assuming you have multiple version of python2 installed.

and to make use of this when installing modules, just edit the setup file to include that line as the first line, and then avoid putting python in the command line

assuming you use batch files to install modules like i do, where most people put:

python setup.py install

i then use:

setup.py install

this ensures that the setup script dictates which version of python it is installed to

i also found after a while of juggling python 2+3 that it made it easier for me to edit the registry so that when i right click a python file i could open it with idle 2 or 3.

EDIT: i should mention that this only works properly when python3 was the last installed, as python 2 sets unfriendly values in the registry, and passes directly to the python2 version rather than checking the file first

Upvotes: -1

jhermann
jhermann

Reputation: 2101

Use virtualenv and nodeenv and have any version combination you want.

Upvotes: 2

Related Questions