gpt4 book ai didi

python - FANN Python 绑定(bind)失败

转载 作者:太空宇宙 更新时间:2023-11-04 01:28:08 27 4
gpt4 key购买 nike

我刚刚构建并安装了 libfann以及相关的 python 绑定(bind)。 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

有人知道怎么解决吗?

最佳答案

我有一个类似的问题,但在 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.

关于python - FANN Python 绑定(bind)失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16198113/

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