废话不多说,解决办法:
#pip安装findspark
pip install findspark
#在程序中添加一以下代码
import findspark
findspark.init()
问题解决:
主要报错信息:
py4j.protocol.Py4JNetworkError: Error while receiving
ERROR:py4j.java_gateway:An error occurred while trying to connect to the Java server (127.0.0.1:59912)
完整报错信息:
D:\Anaconda\python.exe F:/pythonworkspace/mypyspark/test0416.py
Traceback (most recent call last):
File "F:/pythonworkspace/mypyspark/test0416.py", line 8, in <module>
sc = SparkContext("local","first app")
File "D:\Anaconda\lib\site-packages\pyspark\context.py", line 136, in __init__
conf, jsc, profiler_cls)
File "D:\Anaconda\lib\site-packages\pyspark\context.py", line 213, in _do_init
self._encryption_enabled = self._jvm.PythonUtils.getEncryptionEnabled(self._jsc)
File "D:\Anaconda\lib\site-packages\py4j\java_gateway.py", line 1487, in __getattr__
"{0}.{1} does not exist in the JVM".format(self._fqn, name))
py4j.protocol.Py4JError: org.apache.spark.api.python.PythonUtils.getEncryptionEnabled does not exist in the JVM
�ɹ�: ����ֹ PID 10140 (���� PID 9080 �ӽ���)�Ľ��̡�
�ɹ�: ����ֹ PID 9080 (���� PID 14992 �ӽ���)�Ľ��̡�
�ɹ�: ����ֹ PID 14992 (���� PID 8740 �ӽ���)�Ľ��̡�
ERROR:root:Exception while sending command.
Traceback (most recent call last):
File "D:\Anaconda\lib\site-packages\py4j\java_gateway.py", line 1152, in send_command
answer = smart_decode(self.stream.readline()[:-1])
File "D:\Anaconda\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Anaconda\lib\site-packages\py4j\java_gateway.py", line 985, in send_command
response = connection.send_command(command)
File "D:\Anaconda\lib\site-packages\py4j\java_gateway.py", line 1164, in send_command
"Error while receiving", e, proto.ERROR_ON_RECEIVE)
py4j.protocol.Py4JNetworkError: Error while receiving
ERROR:py4j.java_gateway:An error occurred while trying to connect to the Java server (127.0.0.1:59912)
Traceback (most recent call last):
File "D:\Anaconda\lib\site-packages\py4j\java_gateway.py", line 929, in _get_connection
connection = self.deque.pop()
IndexError: pop from an empty deque
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Anaconda\lib\site-packages\py4j\java_gateway.py", line 1067, in start
self.socket.connect((self.address, self.port))
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
Process finished with exit code 1