2013-04-24 91 views
2

我剛剛構建並安裝了libfann和關聯的python綁定。蟒蛇設置似乎正常運行:FANN Python綁定失敗

$ sudo python setup.py install 
Running SWIG before: swig -c++ -python pyfann/pyfann.i 
running install 
running build 
running build_py 
copying pyfann/libfann.py -> build/lib.macosx-10.5-x86_64-2.7/pyfann 
running build_ext 
building 'pyfann._libfann' extension 
gcc -fno-strict-aliasing -I/Users/dwilliams/Desktop/Anaconda/include -arch x86_64 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DSWIG_COMPILE -I../src/include -I/Users/dwilliams/Desktop/Anaconda/include/python2.7 -c pyfann/pyfann_wrap.cxx -o build/temp.macosx-10.5-x86_64-2.7/pyfann/pyfann_wrap.o 
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ 
g++ -bundle -undefined dynamic_lookup -L/Users/dwilliams/Desktop/Anaconda/lib -arch x86_64 -arch x86_64 build/temp.macosx-10.5-x86_64-2.7/pyfann/pyfann_wrap.o ../src/doublefann.o -o  build/lib.macosx-10.5-x86_64-2.7/pyfann/_libfann.so 
running install_lib 
creating /Users/dwilliams/Desktop/Anaconda/lib/python2.7/site-packages/pyfann 
copying build/lib.macosx-10.5-x86_64-2.7/pyfann/__init__.py ->  /Users/dwilliams/Desktop/Anaconda/lib/python2.7/site-packages/pyfann 
copying build/lib.macosx-10.5-x86_64-2.7/pyfann/_libfann.so -> /Users/dwilliams/Desktop/Anaconda/lib/python2.7/site-packages/pyfann 
copying build/lib.macosx-10.5-x86_64-2.7/pyfann/libfann.py -> /Users/dwilliams/Desktop/Anaconda/lib/python2.7/site-packages/pyfann 

但隨後導入失敗:

$ python -c 'import pyfann' 
Traceback (most recent call last): 
    File "<string>", line 1, in <module> 
    File "pyfann/__init__.py", line 4, in <module> 
    import libfann 
    File "pyfann/libfann.py", line 26, in <module> 
    _libfann = swig_import_helper() 
    File "pyfann/libfann.py", line 18, in swig_import_helper 
    import _libfann 
ImportError: No module named _libfann 

有誰知道如何解決這個問題?

回答

2

我有一個類似的問題,但在Mac OS 10.7上使用python 3。我下面的工作,所以希望它可以幫助你了一點:

我的錯誤,類似於你:

>>> import pyfann 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pyfann/__init__.py", line 4, in <module> 
    import libfann 
ImportError: No module named 'libfann' 

所以,我有一個文件__init__.py內四處一看,它看起來像這樣:

# 
# Fast Artificial Neural Network library for Python 
# 
import libfann 
__all__ = [ 
    'libfann' 
] 

出於某種原因,無法找到libfann,但libfann是完全相同的文件夾__init__.py。也許我們可以編輯__init__.py並告訴它libfann是:

# 
# Fast Artificial Neural Network library for Python 
# 

# import imp so we can load modules ourselves rather than through import magic 
import imp 

# try to load libfann, giving the exact path of where libfann resides 
imp.load_source ('libfann','/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pyfann/libfann.py') 

然後嘗試和運行的一個例子:

python3 ~/Downloads/FANN-2.2.0-Source/python/examples/simple_train.py 
FANN Error 1: Unable to open configuration file "../../examples/xor.data" for reading. 
FANN Error 2: Unable to open configuration file "nets/xor_float.net" for writing. 

我不得不打開simple_train.py並輸入完整路徑,在那裏抱怨它無法找到的配置文件,但現在運行正常:

python3 ~/Downloads/FANN-2.2.0-Source/python/examples/simple_train.py 
Max epochs 100000. Desired error: 0.0001000000. 
Epochs   1. Current error: 0.2500073016. Bit fail 4. 
Epochs   39. Current error: 0.0000279390. Bit fail 0. 
1

在我的情況「進口fann2.libfann爲libfann」工作。

Thomas