Skip to content

Commit 25b8ea6

Browse files
authored
Merge pull request #152 from Distributive-Network/will/install-error-when-npm-not-on-system
Add actionable error message for no npm on system during pip install
2 parents 64b9da2 + 8f590f1 commit 25b8ea6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

python/pminit/post-install-hook.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import subprocess
22
import sys
3+
import shutil
34

45
def execute(cmd: str):
56
popen = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT,
@@ -14,7 +15,25 @@ def execute(cmd: str):
1415
raise subprocess.CalledProcessError(return_code, cmd)
1516

1617
def main():
17-
execute("cd pythonmonkey && npm i --no-package-lock") # do not update package-lock.json
18+
node_package_manager = 'npm'
19+
# check if npm is installed on the system
20+
if (shutil.which(node_package_manager) is None):
21+
print("""
22+
23+
PythonMonkey Build Error:
24+
25+
26+
* It appears npm is not installed on this system.
27+
* npm is required for PythonMonkey to build.
28+
* Please install NPM and Node.js before installing PythonMonkey.
29+
* Refer to the documentation for installing NPM and Node.js here: https://nodejs.org/en/download
30+
31+
32+
""")
33+
raise Exception("PythonMonkey build error: Unable to find npm on the system.")
34+
else:
35+
execute(f"cd pythonmonkey && {node_package_manager} i --no-package-lock") # do not update package-lock.json
1836

1937
if __name__ == "__main__":
2038
main()
39+

0 commit comments

Comments
 (0)