無法在 python 2.7.10 中導入集群 (Cannot import cluster in python 2.7.10)


問題描述

無法在 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)

(by r.zjeffmcc)

參考文件

  1. Cannot import cluster in python 2.7.10 (CC BY‑SA 2.5/3.0/4.0)

#Python #python-2.7 #cluster-computing






相關問題

如何從控制台中導入的文件中訪問變量的內容? (How do I access the contents of a variable from a file imported in a console?)

在 python 3.5 的輸入列表中添加美元符號、逗號和大括號 (Adding dollar signs, commas and curly brackets to input list in python 3.5)

為 KeyError 打印出奇怪的錯誤消息 (Strange error message printed out for KeyError)

django 1.9 中的 from django.views.generic.simple import direct_to_template 相當於什麼 (What is the equivalent of from django.views.generic.simple import direct_to_template in django 1.9)

查詢嵌入列表中的數組 (Querying for array in embedded list)

如何在 Python 中搜索子字符串是否在二進製文件中? (How to search if a substring is into a binary file in Python?)

為什麼要避免 while 循環? (Why avoid while loops?)

使用python的json模塊解析json請求 (Parse a json request using json module of python)

為什麼使用 py2app 模塊創建 mac 文件時出現錯誤? (Why i am getting Error when creating mac file using py2app module?)

當 python 線程在網絡調用(HTTPS)中並且發生上下文切換時會發生什麼? (What happens when the python thread is in network call(HTTPS) and the context switch happens?)

如何繪製一條帶斜率和一個點的線?Python (How to plot a line with slope and one point given? Python)

Pickle 找不到我不使用的模塊? (Pickle can't find module that I am not using?)







留言討論