1

I am trying to deploy a smart contract on Azure Blockchain Service. I have created a blockchain consortium and connected it to VSCode extension for Azure Blockchain Service. But when I am trying to run the New Solidity Project command from Command Palette, I am getting the following:

[Execute command] × Setting up box
[Execute command] Error: Command failed: npm install
npm WARN deprecated fs-promise@2.0.3: Use mz or fs-extra^3.0 with Promise 
Support
npm WARN deprecated tar.gz@1.0.7: ⚠️  WARNING ⚠️ tar.gz module has been 
deprecated and your application is vulnerable. Please use tar module 
instead: https://npmjs.com/tar
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: 
C:\Users\manul\AppData\Local\Programs\Python\Python37-32\python.EXE -c 
import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:294:12)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:962:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit 
(internal/child_process.js:251:5)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program 
Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node- 
gyp.js" "rebuild"
gyp ERR! cwd 
d:\Coding\VSProjects\SecureElectronicVoting\.vscode\node_modules\scrypt
gyp ERR! node -v v10.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 
(node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for 
fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: 
{"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! scrypt@6.0.3 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the scrypt@6.0.3 install script.
npm ERR! This is probably not a problem with npm. There is likely 
additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\manul\AppData\Roaming\npm-cache\_logs\2019-08- 
15T22_18_54_838Z-debug.log

at checkExecSyncError (child_process.js:616:11)
at execSync (child_process.js:653:13)
at Object.installBoxDependencies (C:\Users\manul\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-box\lib\utils\unbox.js:118:1)
at Object.setUpBox (C:\Users\manul\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-box\lib\utils\index.js:62:1)
at Object.unbox (C:\Users\manul\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-box\box.js:58:1)
[Execute command] Truffle v5.0.32 (core: 5.0.32)
Node v10.15.0
[Execute command] Finished running command

I understand that this is because this command is trying to use Python3 while it should use Python2.7 (so that the print "%s.%s.%s" doesn't give a syntax error). I tried changing the python.pythonpath in settings.json to C:/Python27/python.exe and changing the python interpreter in vscode to Python2.7, but it still gives error. I have both paths to python3 and python2.7 in my windows path variable.

user46625
  • 31
  • 2

1 Answers1

1

You can identify which Python version node-gyp should use in one of the following ways:

  1. If node-gyp is called by way of npm, and you have multiple versions of Python installed, then you can set npm's 'python' config key to the appropriate value:

$ npm config set python /path/to/executable/python 
  1. If the PYTHON environment variable is set to the path of a Python executable, then that version will be used, if it is a compatible version.

  2. If the NODE_GYP_FORCE_PYTHON environment variable is set to the path of a Python executable, it will be used instead of any of the other configured or builtin Python search paths. If it's not a compatible version, no further searching will be done.

You can use set command in cmd dispaly environment variable.

PS: Using node-gyp in Windows needs Visual C++ build tools, Python 2.7 (v3.x.x is not supported) and some config. You can

Install all the required tools and configurations using Microsoft's windows-build-tools by running npm install -g windows-build-tools from an elevated PowerShell (run as Administrator).

See:

set python version: nodejs/node-gyp: Node.js native addon build tool

Environment setup and configuration: nodejs-guidelines/windows-environment.md at master · microsoft/nodejs-guidelines

my other answer: https://stackoverflow.com/a/59370747/11949765

feng zhang
  • 1,193
  • 7
  • 8