gpt4 book ai didi

python - 为 python 设置 Thrift 模块时出错

转载 作者:太空宇宙 更新时间:2023-11-03 19:38:02 25 4
gpt4 key购买 nike

我正在尝试设置thrift为了与 Cassandra 合并,所以当我运行

setup.py

它将此消息放入命令行

running build
running build_py
running build_ext
building 'thrift.protocol.fastbinary' extension
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python26\include -IC:\Pytho
n26\PC -c src/protocol/fastbinary.c -o build\temp.win32-2.6\Release\src\protocol
\fastbinary.o
src/protocol/fastbinary.c:24:24: netinet/in.h: No such file or directory
src/protocol/fastbinary.c:85:4: #error "Cannot determine endianness"
src/protocol/fastbinary.c: In function `writeI16':
src/protocol/fastbinary.c:295: warning: implicit declaration of function `htons'

src/protocol/fastbinary.c: In function `writeI32':
src/protocol/fastbinary.c:300: warning: implicit declaration of function `htonl'

src/protocol/fastbinary.c: In function `readI16':
src/protocol/fastbinary.c:688: warning: implicit declaration of function `ntohs'

src/protocol/fastbinary.c: In function `readI32':
src/protocol/fastbinary.c:696: warning: implicit declaration of function `ntohl'

error: command 'gcc' failed with exit status 1

在这个问题上需要一些帮助。我已经安装了 MigW32

谢谢。

最佳答案

通过对源文件进行一些调整,可以将其与 MINGW 一起安装在 Windows 上。我正在使用 thrift 0.9.1 和 Python 27

我遵循的步骤是:

  1. 如果您使用的是 Python 2.7,请按照 minGW 的正常设置步骤和解决方法进行操作。特别是,您可能需要打开文件 C:\Python27\Lib\distutils\cygwinccompiler.py,并修改类 Mingw32CCompiler 以删除对 -mno-cygwin 选项的所有引用。此选项已弃用,如果保留该选项,将导致编译器因错误而停止。

  2. 打开 fastbinary.c 并添加以下包含语句,

#include <stdbool.h>,

这包括 true/false 的定义,否则将导致编译失败。 (我假设它们默认包含在 MSVC 中?)

3) 修改setup.py文件,告诉链接器链接到ws2_32.lib。这是使用 MSVC 上的编译指示注释来完成的,但 gcc 不支持此选项。所以你的 ext_modules 应该是这样的:

ext_modules = [
Extension('thrift.protocol.fastbinary',
sources = ['src/protocol/fastbinary.c'],
libraries=['ws2_32'],
include_dirs = include_dirs,
)
],

4) 使用 setup.py 正常构建

在我的设置中,当使用 C 扩展而不是纯 python 时,我没有获得太大的速度改进(大约有 5% 的差异),因此,除非在极端情况下,否则这样做的努力可能是不合理的。

关于python - 为 python 设置 Thrift 模块时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2387816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com