Python package managers and Node.js

后端 未结 2 629
天涯浪人
天涯浪人 2020-12-12 01:50

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 suppl

相关标签:
2条回答
  • 2020-12-12 01:53

    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.)

    0 讨论(0)
  • 2020-12-12 02:20

    I suspect that this is because the Anaconda Prompt is just some weird shortcut that sets up some variables for cmd.exe

    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 your conda.exe is located at

    C:\Users\dream\Anaconda3\Scripts\conda.exe
    

    Start a clean cmd.exe session, where conda is undefined (i.e., not Anaconda Prompt). Then try things like

    C:\Users\dream\Anaconda3\Scripts\conda.exe run where python
    

    or, if you have another env, say my_env you can also do

    C:\Users\dream\Anaconda3\Scripts\conda.exe run -n my_env where python
    

    to 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

    var exec = require('child_process').exec;
    exec('C:\Users\dream\Anaconda3\Scripts\conda.exe run python hello.py', ..callback)
    

    Not sure if you'll need the shell specified in this case.

    0 讨论(0)
提交回复
热议问题