已安装并识别的Python模块,但无法在Ubuntu的代码或Python 2.7.1解释器中导入
我在尝试让一个Python C模块运行时遇到了麻烦。我正在安装deltaLDA模块,具体信息可以在这里找到。我按照README文件里的说明进行了操作。和往常一样,我输入了:
sudo python setup.py install
一切都按预期进行,我想我没有出错,得到了这个输出:
running build
running build_ext
building 'deltaLDA' extension
C compiler: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC
creating build
creating build/temp.linux-i686-2.7
compile options: '-I/media/Hub/DropBox/Dropbox/Betazeta/Software/LDA/deltaLDA -I/usr/lib/pymodules/python2.7/numpy/core/include -I/usr/include/python2.7 -c'
extra options: '-O3 -Wall'
gcc: deltaLDA.c
In file included from /usr/include/python2.7/Python.h:8:0,
from deltaLDA.c:22:
/usr/include/python2.7/pyconfig.h:1155:0: warning: "_POSIX_C_SOURCE" redefined
/usr/include/features.h:214:0: note: this is the location of the previous definition
deltaLDA.c:686:1: warning: function declaration isn’t a prototype
creating build/lib.linux-i686-2.7
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions build/temp.linux-i686-2.7/deltaLDA.o -o build/lib.linux-i686-2.7/deltaLDA.so
running install_lib
copying build/lib.linux-i686-2.7/deltaLDA.so -> /usr/local/lib/python2.7/dist-packages
running install_egg_info
Removing /usr/local/lib/python2.7/dist-packages/deltaLDA-0.1.1.egg-info
Writing /usr/local/lib/python2.7/dist-packages/deltaLDA-0.1.1.egg-info
但是当我尝试导入deltaLDA模块时,却出现了以下错误:
>>> from deltaLDA import deltaLDA
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named deltaLDA
我用help('modules')或者pip freeze命令检查已安装的模块时,发现deltaLDA在两个列表中都有,但我就是无法导入它。希望有人能帮帮我。
谢谢!
更新:
我还检查了sys.path,发现'/usr/local/lib/python2.7/dist-packages'
在其中。如果我尝试像from deltaLDA import *
那样导入所有内容,还是会出现同样的错误。在解释器中我也试过dir(deltaLDA)
,结果也显示“No module name”的错误。也许deltaLDA模块有问题?有没有人能试着安装一下?
解决了
我检查了dist-packages中的.so和egg-info文件的权限,发现它们不可读,我也不知道为什么。我只是运行了一个sudo chmod 777命令,结果现在可以用了!
1 个回答
1
首先试试这个
>>> import deltaLDA
如果这个能成功的话,可以查看一下文档,或者像@arunkumar说的那样查看一下dir(deltaLDA)。如果不行的话,请把你的sys.path和egg-info的详细信息发出来。