最近在學習研究pyspark機器學習算法,執行代碼出現如下異常:
19/06/29 10:08:26 ERROR Shell: Failed to locate the winutils binary in the hadoop binary path
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:379)
at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:394)
at org.apache.hadoop.util.Shell.<clinit>(Shell.java:387)
at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:80)
...........
19/06/29 10:08:26 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:379)
at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:394)
at org.apache.hadoop.util.Shell.<clinit>(Shell.java:387)
at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:80)
...........
19/06/29 10:08:26 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
從程序運行度方面來講,這個異常並不影響spark程序的繼續執行。可是做爲一個程序員看到異常就如出現bug,必須讓這種異常消失!
分析異常:根據提示應該是Hadoop binaries.中缺乏winutils.exe這個配置。
解決方法:
1.首先檢查本地window環境是否已經安裝hadoop,若沒有則先配置hadoop環境變量
1)下載Hadoop,我本次操做使用的是hadoop-2.7.3,固然你能夠根據本身需求去官網下載
官網下載地址:
網盤分享我使用的版本:
連接: https://pan.baidu.com/s/1-ssNBynSzrC5iG5ozwqAUA 提取碼: zdu5
2)配置windows環境變量。本機是windows10系統
先添加HADOOP_HOME配置

在配置path路徑:html
3) 下載winutils.exe,hadoop.dll放到hadoop環境的bin目錄,建議儘可能使用版本匹配的,必然hadoop-2.6就使用2.6版本的。2.7版本就使用2.7.。理論上2.7版本能夠使用在2.6版本上java
這裏提供hadoop-2.7.3版本的這2個文件:連接: https://pan.baidu.com/s/1r5rZWqU2O7wu2WtAhmt1KA 提取碼: pxr9程序員

4)重啓電腦再次測試 異常提示消失算法
提醒:這個異常提示並不必定是spark程序開發時纔會出現。在作hadoop程序開發必然寫mapreduce程序時 也會遇到一樣狀況。操做方法一致便可。apache
原文出處:https://www.cnblogs.com/mdlcw/p/11106218.htmlwindows