#!/bin/sh
# run this script to generate library for Floyd's
# algorithm library
echo "generating input files using SWIG ..."
swig -python floyd.i
echo "compiling ..."
# change compiler if you use other than gcc
gcc -c floyd.c floyd_wrap.c -I/usr/include/python2.6 -fPIC
echo "linking ..."
ld -shared floyd.o floyd_wrap.o -o _floyd.so
#echo "for SELinux you must run chcon ..."
#chcon -t textrel_shlib_t _floyd.so
python demo.py
Calculating distance matrix ............ 2.24 s
Using epsilon-isomap, epsilon = 0.500000, calculating 2-dimensional embedding
Calculating graph matrix ............... 1.21 s
Calculating the shortest path matrix ... 2.22 s
Multidimensionally scalling ............ 7.11 s
Total procedure ........................ 12.79 s
这个源代码已经有5年多的历史了,floyd的构建脚本看起来采用了硬编码的python2.4。你知道吗
很明显,您的
floyd
模块没有构建。您很可能需要返回到构建步骤并确保正确地生成了_floyd.so
。你知道吗如果构建正确,则不会失败:
python -c "import _floyd"
我看了代码,因为Isomap是一个很酷的算法。代码看起来不像是由熟悉Python的人编写的,整个floyd扩展模块编译有点粗制滥造——它实际上不是为我构建的,我很确定这就是你的问题(他们捕获模块的导入异常并打印出你给出的错误)。你知道吗
我将
build_floyd.sh
中的一些硬编码内容更改为系统的不同硬编码值。(一个合适的构建系统将使这变得不必要)。下面是我的Ubuntu系统的工作原理。我测试过了,运行正常。你知道吗您可能还需要将
demo.py
中的第一行更改为#!/usr/bin/env python
。你知道吗在pysomap目录中,创建设置.py包含以下内容的文件:
构建
_floyd
扩展(假设安装了与Python distutils兼容的C编译器):跑演示.py地址:
相关问题 更多 >
编程相关推荐