問題描述
無法在 python 2.7.10 中導入集群 (Cannot import cluster in python 2.7.10)
我是集群新手,剛剛安裝了集群包(命令行:pip install cluster),想導入集群。但由於某種原因,我一直收到這個:
>>> import cluster
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site‑packages/cluster/__init__.py", line 25, in <module>
__version__ = resource_string('cluster','version.txt').decode('ascii').strip()
File "/Library/Python/2.7/site‑packages/setuptools‑1.1.6‑py2.7.egg/pkg_resources.py", line 896, in resource_string
File "/Library/Python/2.7/site‑packages/setuptools‑1.1.6‑py2.7.egg/pkg_resources.py", line 1305, in get_resource_string
File "/Library/Python/2.7/site‑packages/setuptools‑1.1.6‑py2.7.egg/pkg_resources.py", line 1426, in _get
IOError: [Errno 2] No such file or directory: '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site‑packages/cluster/version.txt'
我的“pip install cluster”命令說
Requirement already satisfied (use ‑‑upgrade to upgrade): cluster in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site‑packages
我可以做些什麼來開始使用集群嗎?我知道 scipy 可能也有集群功能,但如果可能的話,我想使用集群包。
謝謝!
參考解法
方法 1:
Well, the pypi page for 'cluster' says you have to import one of the kinds of clustering, as in:
>>> from cluster import HierarchicalClustering
>>> data = [12,34,23,32,46,96,13]
>>> cl = HierarchicalClustering(data, lambda x,y: abs(x‑y))
or
>>> from cluster import KMeansClustering
>>> cl = KMeansClustering([(1,1), (2,1), (5,3), ...])
>>> clusters = cl.getclusters(2)