Python 2.7子流程

时间:2017-01-15 03:52:21

标签: python macos python-2.7 subprocess flopy

我有一个使用名为flopy的包的python脚本。我的脚本为fortran可执行文件生成一系列输入。 Flopy将这些文件写入文本文件,然后调用fortran可执行文件,该文件使用文本文件来运行模型。

我正在使用mac(OSX),我从python.org下载了python 2.7,即我没有使用Apple系统版本的python。我正在使用的python版本在Library / Frameworks / Python.Frameworks /

如果我从终端窗口调用它,我可以运行我的脚本(输入:

Python myscriptname.py

但是,如果我通过IDLE(我下载的python附带的版本)运行我的脚本,则会返回错误:

Traceback (most recent call last):
  File "/Users/neilthomas/RotatedModel_v4_Tr_mfnwt.py", line 355, in <module>
    success, mfoutput = mf.run_model(silent=False, pause=False)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/flopy/mbase.py", line 638, in run_model
normal_msg=normal_msg)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/flopy/mbase.py", line 1034, in run_model
stdout=sp.PIPE, stderr=sp.STDOUT, cwd=model_ws)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory 

文件'mfnwt'绝对存在。我确定我错过了一些明显的东西,但是我需要做些什么才能让IDLE通过它使用的shell运行程序/子进程?感谢。

1 个答案:

答案 0 :(得分:1)

这里的问题是你必须确定你正在调用的特定MODFLOW可执行文件(在你的情况下是'mfnwt')。我对MODFLOW 2000文件做了同样的事情:

mf = flopy.modflow.mf.Modflow(modelname,namefile_ext='nam',version='mf2k',exe_name='/home/MODFLOW-and-related-codes/build-08/bin-windows/mf2k.exe')

在您的情况下,您会做类似的事情,只替换version='mf2k'exe_name=path以匹配存储MODFLOW文件的位置。

有关详细信息,请参阅文档:https://modflowpy.github.io/flopydoc/mf.html