2012-03-29 61 views
2

正如標題所說,我有問題在Fedora下啓動一個新的子進程。現在的情況是,我有一個主要的Python腳本從我開始使用一對夫婦的其他蟒蛇過程:Fedora 16,python subprocess.Popen從IDE vs終端

import subprocess 
subprocess.Popen(['python', '-m', 'first_child.run', 'start'], shell=False) 

現在這個工作在MacOS,Debian和窗戶的罰款。在Fedora上,如果我從Aptana 3 IDE它也可以運行它,唯一的問題是,當我試圖從終端,從哪裏獲得運行這個主要紙條:

OSError: [Errno 2] No such file or directory 

你有任何IDEEA什麼都可以的問題在這裏?

問候, 波格丹

+1

首先想到的是SELinux,但我不知道要檢查什麼。 – 2012-03-29 15:07:13

+0

無論如何,你爲什麼不使用['multiprocessing'](http://docs.python.org/py3k/library/multiprocessing.html)模塊? – 2012-03-29 15:09:42

+0

要檢查SELinux干擾,請在運行腳本時尾巴「/ var/log/audit/audit.log」。 – Charles 2012-03-29 16:45:03

回答

1

很抱歉,如果這是你已經想到的東西 - 但OSERROR從通話中最常見的原因是子進程,它找不到過程

http://docs.python.org/library/subprocess.html#exceptions

你絕對可以肯定python在你的路徑嗎?

我知道你可能會指出你從python可執行文件運行這個腳本 - 但我想我會採取一些措施,或許你指定了從終端運行python的完整路徑。

爲了好玩,在調用子前的權利,你可以放棄你的PATH

import os 
print os.environ['PATH'] 
1

這是你的當前工作目錄。我不認爲問題是它找不到python,問題是它找不到first_child.run

在啓動子進程之前嘗試打印os.getcwd(),並查看它在終端與IDE中是否不同。

在附註中,使用sys.executable作爲您在子進程中使用的python可能更可靠,而不僅僅是說python。例如,subprocess.Popen([sys.executable, '-m', 'first_child.run', 'start'], shell=False)