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 : '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