我试图在spark中运行Kmeans聚类,为此我得到一个例外

时间:2016-06-16 18:42:27

标签: apache-spark pyspark k-means apache-spark-mllib

**Python Version = 2.6.6**

**numpy version = 1.3.0**  

**** The python file dokmeans.py is located in /home/cloudera****  






 Welcome to
          ____              __
         / __/__  ___ _____/ /__
        _\ \/ _ \/ _ `/ __/  '_/
       /__ / .__/\_,_/_/ /_/\_\   version 1.3.0
          /_/

    Using Python version 2.6.6 (r266:84292, Feb 22 2013 00:00:18)
    SparkContext available as sc, HiveContext available as sqlCtx.
    >>> exec(open('dokmeans.py').read())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<string>", line 5, in <module>
      File "/usr/lib/spark/python/pyspark/mllib/__init__.py", line 26, in <module>
        raise Exception("MLlib requires NumPy 1.4+")
    Exception: MLlib requires NumPy 1.4+
    >>> from pyspark.mllib.clustering import KMeans,KMeansModel
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/spark/python/pyspark/mllib/__init__.py", line 26, in <module>
        raise Exception("MLlib requires NumPy 1.4+")
    Exception: MLlib requires NumPy 1.4+

2 个答案:

答案 0 :(得分:1)

嗯,错误代码全部说明了。要使用MLlib,您需要安装numpy 1.4。你已经安装了1.3。

答案 1 :(得分:-1)

mllib代码中存在一个错误,它无法正确解释numpy版本。它将1.10解释为1.1,因此对numpy版本的检查失败。

请更改以下文件中的代码 / usr / lib中/火花/蟒/ pyspark / mllib /的初始化的.py

从:

**if numpy.version.version < '1.4':**
raise Exception("MLlib requires NumPy 1.4+")

为:

ver = [int(x) for x in numpy.version.version.split('.')[:2]]
if ver < [1, 4]:
    raise Exception("MLlib requires NumPy 1.4+")