安装pyml后,import PyML出错:
>>> import PyML
>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "PyML/__init__.py", line 4, in <module>
from PyML.containers import *
File "PyML/containers/__init__.py", line 3, in <module>
VectorDataSet = __import__('PyML.containers.vectorDatasets', fromlist=['']).VectorDataSet
File "PyML/containers/vectorDatasets.py", line 5, in <module>
from PyML.containers.baseDatasets import WrapperDataSet, BaseVectorDataSet
File "PyML/containers/baseDatasets.py", line 4, in <module>
from PyML.containers import ker
File "PyML/containers/ker.py", line 6, in <module>
from ext import ckernel
File "PyML/containers/ext/ckernel.py", line 25, in <module>
_ckernel = swig_import_helper()
File "PyML/containers/ext/ckernel.py", line 17, in swig_import_helper
import _ckernel
ImportError: No module named _ckernel
最后发现是在 pyml 安装包解压缩目录下运行的原因,因为 PyML/ 目录下已经有一个init.py,Python把这个目录当成了一个库,所以当想要 import PyML 的时候,Python就会在这个解压缩目录里面找,不是想要使用的那个 PyML库.
解决办法:进去其他任意目录,重新运行即可。
例如:
#cd /
# python
Python 2.7.5 (default, Aug 4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyML
>>> PyML.__version__
'0.7.14'
参考 https://sourceforge.net/p/pyml/discussion/393034/thread/0ae37eac/
You probably tried to import the PyML module while in the directory created after extracting the tar.gz. That directory has a
PyML/
directory with a file called
__init__.py
in it. The existence of that file make that directory a Python module. So, when you tried to import the PyML module, Python found it there, and that module wasn't the one you wanted.
The "solution" is to
cd
into some other directory and try the import again.