2017-02-14 22 views
5

khi chạy sau trong môi trường Python 3.5 Jupyter Tôi nhận được lỗi dưới đây. Bất kỳ ý tưởng về những gì đang gây ra nó?findspark.init() IndexError: danh sách chỉ mục ngoài phạm vi lỗi

import findspark 
findspark.init() 

lỗi:

IndexError        Traceback (most recent call 
last) <ipython-input-20-2ad2c7679ebc> in <module>() 
     1 import findspark 
----> 2 findspark.init() 
     3 
     4 import pyspark 

/.../anaconda/envs/pyspark/lib/python3.5/site-packages/findspark.py in init(spark_home, python_path, edit_rc, edit_profile) 
    132  # add pyspark to sys.path 
    133  spark_python = os.path.join(spark_home, 'python') 
--> 134  py4j = glob(os.path.join(spark_python, 'lib', 'py4j-*.zip'))[0] 
    135  sys.path[:0] = [spark_python, py4j] 
    136 

IndexError: list index out of range 

Trả lời

2

này rất có thể là do sự biến SPARK_HOME môi trường không được đặt đúng trên hệ thống của bạn. Ngoài ra, bạn chỉ có thể xác định nó khi bạn đang initialising findspark, như vậy:

import findspark 
findspark.init('/path/to/spark/home') 

Sau đó, nó nên tất cả công việc!

2

tôi đã nhận được báo lỗi tương tự và đã có thể làm cho nó hoạt bằng cách nhập thư mục cài đặt chính xác:

import findspark 
# Use this 
findspark.init("C:\Users\PolestarEmployee\spark-1.6.3-bin-hadoop2.6") 
# Test 
from pyspark import SparkContext, SparkConf 

Basically, it is the directory where spark was extracted. In future where ever you see spark_home enter the same installation directory. I also tried using toree to create a kernal instead, but it is failing somehow. A kernal would be a cleaner solution.

0

Bạn cần phải cập nhật SPARK_HOME biến bên bash_profile. Đối với tôi, lệnh sau đây làm việc (trong terminal):

export SPARK_HOME="/usr/local/Cellar/apache-spark/2.2.0/libexec/"

Sau đó, bạn có thể sử dụng làm theo các lệnh:

import findspark 
findspark.init('/usr/local/Cellar/apache-spark/2.2.0/libexec') 
Các vấn đề liên quan