引发 child_exception Errno 2

发布于 2024-09-25 10:51:09 字数 4792 浏览 8 评论 0原文

我正在尝试使用 ctypes 和 ctypeslib 将 C 标头转换为 Python 库。我正在 OSX 10.6.4 (Snow Leopard) 上运行 Python 2.7。
我要转换的头文件是 mcbcio32.h,位于 /header/mcbcio32.h 我希望在同一文件夹中创建一个名为 mcbcio32.xml 的 xml 输出。

我使用以下命令从 ctypeslib 文件夹运行 h2xml.py (它将 c 标头转换为包装的 xml 文件):

$ python h2xml.py /header/mcbcio32.h -o mcbcio32.xml -q -c

输出:

Traceback (most recent call last):
  File "h2xml.py", line 92, in <module>
    sys.exit(main())
  File "h2xml.py", line 86, in main
    compile_to_xml(argv)
  File "h2xml.py", line 79, in compile_to_xml
    parser.parse(files)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypeslib/codegen/cparser.py", line 306, in parse
    self.create_final_xml(include_files, types, None)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypeslib/codegen/cparser.py", line 265, in create_final_xml
    self.create_xml(source, xmlfile)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypeslib/codegen/cparser.py", line 97, in create_xml
    stdin=subprocess.PIPE)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
    errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1201, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

来自什么我可以看出,调用了三个主要脚本:h2xml.py、cparser.py,最后是 subprocess.py。所有这些脚本都是由 Python 开发人员编写的,因此我猜测错误出在我运行发出命令的方式中。

h2xml.py 代码:

"""h2xml - convert C include file(s) into an xml file by running gccxml."""
import sys, os, ConfigParser
from ctypeslib.codegen import cparser
from optparse import OptionParser

def compile_to_xml(argv):
    def add_option(option, opt, value, parser):
        parser.values.gccxml_options.extend((opt, value))

    # Hm, should there be a way to disable the config file?
    # And then, this should be done AFTER the parameters are processed.
    config = ConfigParser.ConfigParser()
    try:
        config.read("h2xml.cfg")
    except ConfigParser.ParsingError, detail:
        print >> sys.stderr, detail
        return 1

    parser = OptionParser("usage: %prog includefile ... [options]")
    parser.add_option("-q", "--quiet",
                      dest="quiet",
                      action="store_true",
                      default=False)

    parser.add_option("-D",
                      type="string",
                      action="callback",
                      callback=add_option,
                      dest="gccxml_options",
                      help="macros to define",
                      metavar="NAME[=VALUE]",
                      default=[])

    parser.add_option("-U",
                      type="string",
                      action="callback",
                      callback=add_option,
                      help="macros to undefine",
                      metavar="NAME")

    parser.add_option("-I",
                      type="string",
                      action="callback",
                      callback=add_option,
                      dest="gccxml_options",
                      help="additional include directories",
                      metavar="DIRECTORY")

    parser.add_option("-o",
                      dest="xmlfile",
                      help="XML output filename",
                      default=None)

    parser.add_option("-c", "--cpp-symbols",
                      dest="cpp_symbols",
                      action="store_true",
                      help="try to find #define symbols - this may give compiler errors, " \
                      "so it's off by default.",
                      default=False)

    parser.add_option("-k",
                      dest="keep_temporary_files",
                      action="store_true",
                      help="don't delete the temporary files created "\
                      "(useful for finding problems)",
                      default=False)

    options, files = parser.parse_args(argv[1:])

    if not files:
        print "Error: no files to process"
        print >> sys.stderr, __doc__
        return 1

    options.flags = options.gccxml_options
    options.verbose = not options.quiet

    parser = cparser.IncludeParser(options)
    parser.parse(files)

def main(argv=None):
    if argv is None:
        argv = sys.argv

    try:
        compile_to_xml(argv)
    except cparser.CompilerError, detail:
        print >> sys.stderr, "CompilerError:", detail
        return 1

if __name__ == "__main__":
    sys.exit(main())

我安装了 GCC-XML,并将 ctypeslib 粘贴到: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ (我的本地 Python 库路径)

如果有任何其他信息有用,请告诉我。预先感谢您的任何帮助。

I'm attempting to convert a C header into a Python library using ctypes and ctypeslib. I'm running Python 2.7, on OSX 10.6.4 (Snow Leopard).
The header-file I am converting is mcbcio32.h, located in /header/mcbcio32.h
I wish to create an xml output in the same folder, named mcbcio32.xml.

I run h2xml.py (which converts the c header into an wrapped xml file) from the ctypeslib folder with the following command:

$ python h2xml.py /header/mcbcio32.h -o mcbcio32.xml -q -c

Output:

Traceback (most recent call last):
  File "h2xml.py", line 92, in <module>
    sys.exit(main())
  File "h2xml.py", line 86, in main
    compile_to_xml(argv)
  File "h2xml.py", line 79, in compile_to_xml
    parser.parse(files)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypeslib/codegen/cparser.py", line 306, in parse
    self.create_final_xml(include_files, types, None)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypeslib/codegen/cparser.py", line 265, in create_final_xml
    self.create_xml(source, xmlfile)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypeslib/codegen/cparser.py", line 97, in create_xml
    stdin=subprocess.PIPE)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
    errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1201, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

From what I can tell, three main scripts are called upon, h2xml.py, cparser.py, and finally subprocess.py. All of these scripts are written by Python developers, and thus I'm guessing the error lies somewhere in how I run the issuing command.

h2xml.py Code:

"""h2xml - convert C include file(s) into an xml file by running gccxml."""
import sys, os, ConfigParser
from ctypeslib.codegen import cparser
from optparse import OptionParser

def compile_to_xml(argv):
    def add_option(option, opt, value, parser):
        parser.values.gccxml_options.extend((opt, value))

    # Hm, should there be a way to disable the config file?
    # And then, this should be done AFTER the parameters are processed.
    config = ConfigParser.ConfigParser()
    try:
        config.read("h2xml.cfg")
    except ConfigParser.ParsingError, detail:
        print >> sys.stderr, detail
        return 1

    parser = OptionParser("usage: %prog includefile ... [options]")
    parser.add_option("-q", "--quiet",
                      dest="quiet",
                      action="store_true",
                      default=False)

    parser.add_option("-D",
                      type="string",
                      action="callback",
                      callback=add_option,
                      dest="gccxml_options",
                      help="macros to define",
                      metavar="NAME[=VALUE]",
                      default=[])

    parser.add_option("-U",
                      type="string",
                      action="callback",
                      callback=add_option,
                      help="macros to undefine",
                      metavar="NAME")

    parser.add_option("-I",
                      type="string",
                      action="callback",
                      callback=add_option,
                      dest="gccxml_options",
                      help="additional include directories",
                      metavar="DIRECTORY")

    parser.add_option("-o",
                      dest="xmlfile",
                      help="XML output filename",
                      default=None)

    parser.add_option("-c", "--cpp-symbols",
                      dest="cpp_symbols",
                      action="store_true",
                      help="try to find #define symbols - this may give compiler errors, " \
                      "so it's off by default.",
                      default=False)

    parser.add_option("-k",
                      dest="keep_temporary_files",
                      action="store_true",
                      help="don't delete the temporary files created "\
                      "(useful for finding problems)",
                      default=False)

    options, files = parser.parse_args(argv[1:])

    if not files:
        print "Error: no files to process"
        print >> sys.stderr, __doc__
        return 1

    options.flags = options.gccxml_options
    options.verbose = not options.quiet

    parser = cparser.IncludeParser(options)
    parser.parse(files)

def main(argv=None):
    if argv is None:
        argv = sys.argv

    try:
        compile_to_xml(argv)
    except cparser.CompilerError, detail:
        print >> sys.stderr, "CompilerError:", detail
        return 1

if __name__ == "__main__":
    sys.exit(main())

I have GCC-XML installed, and the ctypeslib was pasted into:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
(my local Python library path)

If any additional information would be useful, please let me know. Thanks in advance for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随风而去 2024-10-02 10:51:09

问题出在 gcc-xml 的安装上。确保在安装 gcc-xml 时也安装 cmake 函数 (cmake.org)。在 gcc 安装文件夹上正确使用 cmake 解决了我遇到的所有目录问题。

The problem was with the installation of gcc-xml. Make sure when installing gcc-xml to also install the cmake function (cmake.org). Properly using cmake on the gcc install folder solved all the directory problems I was experiencing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文