2010-03-05 118 views
1

我試圖建立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

謝謝。

+0

在我看來,編譯器缺少一些包含它所需的東西(例如「netinet/in.h」)......在Windows中嘗試編譯加載項和模塊等時出現一個常見問題。您可能需要確保GCC可以找到「C:\ Python26 \ include」中的所有文件以及Thrift和Cassandra所需的任何其他庫... – ewall 2010-03-05 17:10:01

+0

仍然收到相同的錯誤,我遵循這裏描述的方法http://code.google.com/p/rdflib/issues/detail?id=104這就是我迄今爲止得到的結果。現在無法解決這個問題。 – Switch 2010-03-06 03:18:02

回答

0

我只成功地安裝了帶MSVC的Thrift。

  • 安裝MSVC
  • 獲取節儉
  • 應用節儉-252-中的python-MSVC-1.diff補丁(google一下)

的fastbinary.c將被修補,但設置。 PY打補丁失敗,從setup.py.rej提示手動更新,這裏的(貌似)正確副本:

from distutils.core import setup, Extension 
import sys 

libraries = [] 

if sys.platform == 'win32': 
    libraries.append('ws2_32') 

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

setup(name = 'Thrift', 
     version = '0.1', 
     description = 'Thrift Python Libraries', 
     author = 'Thrift Developers', 
     author_email = '[email protected]', 
     url = 'http://incubator.apache.org/thrift/', 
     license = 'Apache License 2.0', 
     packages = [ 
     'thrift', 
     'thrift.protocol', 
     'thrift.transport', 
     'thrift.server', 
     ], 
     package_dir = {'thrift' : 'src'}, 
     ext_modules = [fastbinarymod], 
    ) 

字節序測試失敗,修改˚F astbinary.c(約68行):

#ifdef _MSC_VER 
    #define __BYTE_ORDER __LITTLE_ENDIAN 
#endif 

該運行python setup.py install之後,希望你會得到你所需要的。

0

安裝python-dev的

您可以運行: sudo易於得到安裝python-dev的

+0

我猜這是由某人下調的,因爲它沒有直接解決這個問題,但我投了票,因爲它解決了我的問題......通過'pip install pycassa'安裝給出了關於'建造'節儉的錯誤.protocol.fastbinary的'擴展',大概因此不會安裝快速C擴展......你的答案解決了這個問題,謝謝! – Anentropic 2012-11-19 19:52:28

1

有了一點源文件的調整,可以在Windows上使用MinGW安裝。我使用的是節儉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%的差異),所以這樣做的努力可能是不合理的,除非在極端情況下。