Python软件包管理器和Node.js [英] Python package managers and Node.js
问题描述
我正在尝试使用Node.js编译python脚本. python脚本包括我已安装的一些模块. 我的python软件包管理器是Anaconda,因此我尝试在:
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:
我怀疑这是因为Anaconda Prompt只是一些奇怪的快捷方式,它为cmd.exe设置了一些变量(快捷方式指向的位置).
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).
所以我的问题:
我可以直接使用Node.js调用anaconda提示吗? pip也有外壳吗?
Can I call the anaconda prompt directly with Node.js? Does pip also have a shell?
打包程序(pip,anaconda)如何使python可访问模块? ->这是通过某些环境变量实现的吗?
How do the packagers (pip,anaconda) make modules accessible to python? -> Is this through some environment variables?
我可以使用与Python相同的方式准备cmd.exe以便与python一起工作吗?
Can I prepare cmd.exe for work with python the same way that they do?
推荐答案
我怀疑这是因为Anaconda Prompt只是一些怪异的快捷方式,它为cmd.exe设置了一些变量
是的,仅此而已.所以,不,我不认为您可以按建议的那样来称呼它.可能有一种方法可以手动操作cmd.exe
使其像Anaconda Prompt会话一样运行,但我建议尝试...
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...
不确定在Windows中是否可以使用,但是可以使用conda run
在Conda环境中执行.该功能是Conda v4.6中的一项实验性功能(至今仍保留),其明确目的是使人们能够在Conda环境中运行某些内容而无需交互激活它.
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.
首先,您可能应该测试conda run
在Windows上是否可以工作.假设您的conda.exe
位于
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
启动一个干净的cmd.exe
会话,其中未定义conda
(即不是Anaconda Prompt).然后尝试类似
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
或者,如果您有另一个环境,例如说my_env
,您也可以这样做
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
验证要运行的Python解释器是否为指定的解释器.
to verify that the Python interpreter that gets run is the one specified.
如果上述方法可行,那么您应该可以执行类似的操作
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.
这篇关于Python软件包管理器和Node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!