I am trying to compile python scripts using Node.js. The python scripts include some modules I have installed.
My package manager for python is Anaconda, so I tried to supply the {"shell":"path to anaconda prompt"}
option in :
var exec = require('child_process').exec;
exec('python hello.py',{"shell":"path to anaconda prompt"}, ..callback)
However, I get an error:
{ Error: spawn C:\Users\dream\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)\Anaconda Prompt (Anaconda3) ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19)
at onErrorNT (internal/child_process.js:407:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:11)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
errno: 'ENOENT',
code: 'ENOENT',
syscall:
'spawn C:\\Users\\dream\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Anaconda3 (64-bit)\\Anaconda Prompt (Anaconda3)',
path:
'C:\\Users\\dream\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Anaconda3 (64-bit)\\Anaconda Prompt (Anaconda3)',
spawnargs: [ '/d', '/s', '/c', '"python hello.py"' ],
cmd: 'python hello.py' }
stdout:
stderr:
I suspect that this is because the Anaconda Prompt is just some wierd shortcut that sets up some variables for cmd.exe (which is the location the shortcut points to).
So my questions:
Can I call the anaconda prompt directly with Node.js? Does pip also have a shell?
How do the packagers (pip,anaconda) make modules accessible to python? -> Is this through some environment variables?
Can I prepare cmd.exe for work with python the same way that they do?
I don't think you want to call the Anaconda prompt.
Just call python:
python print('hello')
.What happens on the command line if you call:
Anaconda Prompt (Anaconda3) print('hello')
?(This should be a comment, but I cannot comment.)
Yes, that's pretty much it. So, no I don't think you can call it as proposed. There is probably a way to manipulate the
cmd.exe
manually to get it running like an Anaconda Prompt session, but instead I'd propose to try...conda run
Not sure if this will work in Windows, but it might be possible to use
conda run
to execute within the Conda environment. This was introduced (and still remains) as an experimental feature in Conda v4.6, with the express purpose of enabling one to run something inside a Conda environment without interactively having to activate it.Prerequisite
First, you should probably test that
conda run
works on Windows. Let's assume yourconda.exe
is located atStart a clean
cmd.exe
session, whereconda
is undefined (i.e., not Anaconda Prompt). Then try things likeor, if you have another env, say
my_env
you can also doto verify that the Python interpreter that gets run is the one specified.
(Possible) Solution
If the above works, then you should be able to do something like
Not sure if you'll need the shell specified in this case.