pysparkの一般的なエラー、問題、および解決策[継続的な更新]。

一、报错:Py4JError:o46.fitの呼び出し中にエラーが発生しました


環境:Centos7、Python3.7、spark2.4.6、java1.8.0_211、scala2.11.12
エラーコードスニペット:

from pyspark.ml import Pipeline
from pyspark.ml.classification import LogisticRegression
from pyspark.ml.feature import HashingTF, Tokenizer

# (id, text, label) 
training = spark.createDataFrame([
    (0, "a b c d e spark", 1.0),
    (1, "b d", 0.0),
    (2, "spark f g h", 1.0),
    (3, "hadoop mapreduce", 0.0)
], ["id", "text", "label"])
training.show()# tokenizer, hashingTF, and lr.
tokenizer = Tokenizer(inputCol="text", outputCol="words")
hashingTF = HashingTF(inputCol=tokenizer.getOutputCol(), outputCol="features")
lr = LogisticRegression(maxIter=10, regParam=0.001)
pipeline = Pipeline(stages=[tokenizer, hashingTF, lr])

model = pipeline.fit(training)

エラーレポートはおおまかに次のとおりです。[重要な部分を自分でフィルタリングすることをお勧めします]

Exception happened during processing of request from ('127.0.0.1', 48756)
ERROR:root:Exception while sending command.
Traceback (most recent call last):
  File "/root/spark-2.4.4-bin-hadoop2.7/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py", line 1159, in send_command
    raise Py4JNetworkError("Answer from Java side is empty")
py4j.protocol.Py4JNetworkError: Answer from Java side is empty

During handling of the above exception, another exception occurred:
ERROR:py4j.java_gateway:An error occurred while trying to connect to the Java server (127.0.0.1:44278)
py4j.protocol.Py4JError: An error occurred while calling o46.fit
IndexError: pop from an empty deque

During handling of the above exception, another exception occurred:
py4j.protocol.Py4JError: An error occurred while calling o46.fit

During handling of the above exception, another exception occurred:

Py4JError: An error occurred while calling o46.fit

分析:
実行後、このセクションはエラーを引き起こします:

model = pipeline.fit(training)

これは、Alibaba Cloud ECS、Centosシステム、学生のコンピューターで実行したために発生したエラーです。それから私は問題の多くの理由と解決策をインターネットで検索しました、そして私はそれらがすべて失敗したことに気づきました。次に、ローカル仮想マシンに変更して正常に実行しました。ローカル仮想マシンの環境は、Alibaba Cloudが購入した学生用マシンとまったく同じですが、構成が異なります。したがって、構成が低すぎることが問題になるはずです。

一、报错:NameError:name'long 'が定義されていません


環境:Centos7、Python3.7、spark2.4.6、java1.8.0_211、scala2.11.12

エラーの理由:Python3.xにはlong型はなく、int型のみです。Python 2.xには、long型とint型の両方があります。

longをintに変更します。

おすすめ

転載: blog.csdn.net/qq_42658739/article/details/107784679