【问题标题】:make doesn't run .py filemake 不运行 .py 文件
【发布时间】:2012-05-30 14:23:11
【问题描述】:

我正在尝试使用 f2py 从 Fortran 代码创建 Python 模块。我已经为我的项目设置了一个 Makefile。我在 Windows 7 上使用 MinGW 和 Python 3.2.2。当我运行时

f2py.py -c --compiler=mingw32 -m itf itimes-f.f

一切都编译并运行良好。但是,当我在 Makefile 中创建一个目标并运行它时,它会这样做:

> make compilef
f2py.py -c --compiler=mingw32 -m itf itimes-f.f
process_begin: CreateProcess(NULL, env python.exe C:\Python32\Scripts\f2py.py -c
 --compiler=mingw32 -m itf itimes-f.f, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [compilef] Error 2

为什么make 不运行命令,我该如何解决?

编辑:运行输出中显示的命令不起作用:

> env python.exe C:\Python32\Scripts\f2py.py -c --compiler=mingw32 -m itf itimes-f.f
'env' is not recognized as an internal or external command,
operable program or batch file.

但是,以下方法确实有效:

> python.exe C:\Python32\Scripts\f2py.py -c --compiler=mingw32 -m itf itimes-f.f

编辑 2: 这引发了另一个问题 - env 是什么,make 为什么要添加它?

编辑 3: 根据 Florian 的评论,由于 f2py.py 中存在 shebang 行,env 似乎是由 make 添加的。我编辑了 f2py.py,在 shebang 前面添加了一个额外的#。我现在有以下问题:

>make compilef
f2py.py -c --compiler=mingw32 -m itf itimes-f.f
process_begin: CreateProcess(C:\Python32\Scripts\f2py.py, f2py.py -c --compiler=
mingw32 -m itf itimes-f.f, ...) failed.
make (e=193): Error 193
make: *** [compilef] Error 193

【问题讨论】:

  • 当您尝试运行错误消息中给出的命令时?
  • @IgnacioVazquez-Abrams,你指的是哪个命令?
  • env开头的那个。
  • @IgnacioVazquez-Abrams,见编辑。
  • f2py.py 可能以这样的一行开头:#!/usr/bin/env python。这就是env 的来源。 env 只需调用 python 解释器(参见 man page

标签: python numpy makefile f2py


【解决方案1】:

好的,只需 convention 即可编写 makefile,以便它们在标准的 unix 环境中运行。 尽管如此,make 来自 *nix,如果你安装了 make,那么你可能拥有提供基本工具的 msys,并且脚本以 unix 方式执行,不像 windows 那样......

一个适用于我在 windows 上使用 mingw-make 的示例 makefile:

all:
    ./test.py

test.py 的 shebang 为 #!C:\\Python27\\python.exe

或者如果python在PATH中#!python就足够了,原样:

all:
    python test.py

【讨论】:

    猜你喜欢
    • 2016-06-30
    • 2021-03-31
    • 1970-01-01
    • 1970-01-01
    • 2020-09-22
    • 1970-01-01
    • 2018-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多