我正在使用virtualenv运行程序。但是这里生成的multiprocessing.Process默认使用系统python。我该如何强制其使用virtualenv python?
这里打印的是 "/usr/bin/python"。但我需要使用 virtualenv 中的 python。
import os
from multiprocessing import Process
def function1():
# do_something_here
p = Process(func2(), args=(param,))
p.start()
return something
def func2(param):
os.system("which python")
这里打印的是 "/usr/bin/python"。但我需要使用 virtualenv 中的 python。
func2()
作为进程参数,而是使用了func2
,并进行了其他一些修复),它确实返回了virtualenv版本。在生成进程之前,请尝试在主程序中添加os.system("which python")
,看看会发生什么。 - Hannu