Reputation: 3340
In Linux, if I execute this command in the terminal :
ipython '/media/folder1/myscript.py'
it works. But, If I execute in IPython terminal :
import subprocess
cmd_list= ["ipython", '/media/folder1/myscript.py' ]
proc= subprocess.Popen(cmd_list)
I have this error :
cmd_list= ["ipython", filescript]
proc= subprocess.Popen(cmd_list)
Traceback (most recent call last):
File "<ipython-input-47-66f9b0f2ed3f>", line 2, in <module>
proc= subprocess.Popen(cmd_list)
File "/home/linux1/anaconda2/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/home/linux1/anaconda2/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Why sub-process cannot execute this terminal command ?
Upvotes: 0
Views: 642
Reputation: 85432
You need to specify the full path for ipython
.
Type:
which ipython
in a terminal and use the path it tells you with subprocess
:
cmd_list= ["/path/from/which/ipython", '/media/folder1/myscript.py']
Alternatively, you can try with shell=True
:
subprocess.Popen(cmd_list, shell=True)
This might not be recommended, depending on your usage.
Upvotes: 1