2014-06-16 8 views
10

मैं टर्मिनल लाइन से पायस्पार्क चला सकता हूं और सबकुछ ठीक काम करता है।स्पाइडर की तरह PySpark चालू और आईडीई चल रहा है?

~/spark-1.0.0-bin-hadoop1/bin$ ./pyspark 

में आपका स्वागत है

 
     ____    __ 
    /__/__ ___ _____/ /__ 
    _\ \/ _ \/ _ `/ __/ '_/ 
    /__/.__/\_,_/_/ /_/\_\ version 1.0.0 
     /_/ 

जब मैं एक अजगर आईडीई

पर इस की कोशिश करते हैं अजगर संस्करण 2.7.6 (डिफ़ॉल्ट, 27 मई 2014 14:50:58)

हालांकि का उपयोग करने के लिए

import pyspark 

ImportError: No module named pyspark

मैं इसे कैसे आयात करूं आर पायथन पुस्तकालयों जैसे numpy, scikit आदि?

टर्मिनल में काम करना ठीक काम करता है, मैं बस आईडीई में काम करना चाहता था।

+0

अपने पायथनपैथ में pyspark है? क्या विचार में पाइथनपथ अद्यतित है? –

उत्तर

0

pyspark शायद आपके पायथनपैथ चर पर नहीं है। उस स्थान पर जाएं जहां pyspark फ़ोल्डर स्थित है और उस फ़ोल्डर को अपने वर्ग पथ में जोड़ें।

+0

काम नहीं कर रहा है, यह पथ में है और अभी भी काम नहीं कर रहा है – idoda

4

मैंने इस उद्देश्य के लिए स्पष्ट रूप से कुछ समय पहले इस लॉन्चर स्क्रिप्ट को लिखा था। मैं bpython (1) कोड-समापन दुभाषिया और विंग आईडीई, या उस मामले के लिए किसी भी आईडीई के माध्यम से पाइस्पार्क खोल के साथ बातचीत करने में सक्षम होना चाहता था क्योंकि उनके पास कोड पूर्ण होने के साथ-साथ एक पूर्ण विकास अनुभव भी प्रदान किया गया था। केवल 'pyspark' टाइप करके स्पार्क कोर सीखना पर्याप्त नहीं है। तो मैंने यह लिखा। यह क्लौडेरा सीडीएच 5 पर्यावरण में लिखा गया था, लेकिन थोड़ा tweaking के साथ आप इसे अपने पर्यावरण में भी काम करने के लिए प्राप्त कर सकते हैं (यहां तक ​​कि मैन्युअल रूप से स्थापित भी)।

उपयोग कैसे करें:

NOTE: You can place all of the following in your .profile (or equivalent). 
(1) linux$ export MASTER='yarn-client | local[NN] | spark://host:port' 
(2) linux$ export SPARK_HOME=/usr/lib/spark # Your's will vary. 
(3) linux$ export JAVA_HOME=/usr/java/latest # Your's will vary. 
(4) linux$ export NAMENODE='vps00' # Your's will vary. 
(5) linux$ export PYSTART=${PYTHONSTARTUP} # See in-line commends about the reason for the need for this alias to PYTHONSTARTUP. 
(6) linux$ export HADOOP_CONF_DIR=/etc/hadoop/conf # Your's will vary. This one may not be necessary to set. Try and see. 
(7) linux$ export HADOOP_HOME=/usr/lib/hadoop  # Your's will vary. This one may not be necessary to set. Try and see. 

(8) bpython -i /path/to/script/below # The moment of truth. Note that this is 'bpython' (not just plain 'python', which would not give the code completion you desire). 
>>> sc 
<pyspark.context.SparkContext object at 0x2798110> 
>>> 

अब एक IDE साथ प्रयोग के लिए, आप बस कि आईडीई के लिए एक PYTHONSTARTUP स्क्रिप्ट के बराबर निर्दिष्ट करने का तरीका निर्धारित करते हैं, और करने के लिए '/ पथ सेट कि/to/स्क्रिप्ट/नीचे '। उदाहरण के लिए, जैसा कि मैंने नीचे दी गई इन-लाइन टिप्पणियों में वर्णित किया है, विंग आईडीई के लिए आप प्रोजेक्ट के प्रॉपर्टी सेक्शन के अंदर कुंजी/वैल्यू जोड़ी 'PYTHONSTARTUP =/path/to/script/नीचे' सेट करते हैं।

अधिक जानकारी के लिए ऑनलाइन टिप्पणियां देखें।

#! /usr/bin/env python 
# -*- coding: utf-8 -*- 
# 
# =========================================================================== 
# Author: Noel Milton Vega (PRISMALYTICS, LLC.) 
# =========================================================================== 
# Start-up script for 'python(1)', 'bpython(1)', and Python IDE iterpreters 
# when you want a 'client-mode' SPARK Shell (i.e. interactive SPARK shell) 
# environment either LOCALLY, on a SPARK Standalone Cluster, or on SPARK 
# YARN cluster. The code-sense/intelligence of bpython(1) and IDEs, in 
# particular will aid in learning the SPARK core API. 
# 
# This script basically (1) first sets up an environment to launch a SPARK 
# Shell, then (2) launches the SPARK Shell using the 'shell.py' python script 
# provided in the distribution's SPARK_HOME; and finally (3) imports our 
# favorite Python modules (for convenience; e.g. numpy, scipy; etc.). 
# 
# IMPORTANT: 
# DON'T RUN THIS SCRIPT DIRECTLY. It is meant to be read in by interpreters 
# (similar, in that respect, to a PYTHONSTARTUP script). 
# 
# Thus, there are two ways to use this file: 
# # We can't refer to PYTHONSTARTUP inside this file b/c that causes a recursion loop 
# # when calling this from within IDEs. So in step (0) we alias PYTHONSTARTUP to 
# # PYSTARTUP at the O/S level, and use that alias here (since no conflict with that). 
# (0): user$ export PYSTARTUP=${PYTHONSTARTUP} # We can't use PYTHONSTARTUP in this file 
# (1): user$ export MASTER='yarn-client | local[NN] | spark://host:port' 
#  user$ bpython|python -i /path/to/this/file 
# 
# (2): From within your favorite IDE, specify it as your python startup 
#  script. For example, from within a WINGIDE project, set the following 
#  variables within a WING Project: 'Project -> Project Properties': 
#   'PYTHONSTARTUP=/path/to/this/very/file' 
#   'MASTER=yarn-client | local[NN] | spark://host:port' 
# =========================================================================== 
import sys, os, glob, subprocess, random 
namenode = os.getenv('NAMENODE') 
SPARK_HOME = os.getenv('SPARK_HOME') 
# =========================================================================== 


# ================================================================================= 
# This functions emulates the action of "source" or '.' that exists in bash(1), 
# and can be used to set PYTHON environment variables (in Pythons globals dict). 
# ================================================================================= 
def source(script, update=True): 
    proc = subprocess.Popen(". %s; env -0" % script, stdout=subprocess.PIPE, shell=True) 
    output = proc.communicate()[0] 
    env = dict((line.split("=", 1) for line in output.split('\x00') if line)) 
    if update: os.environ.update(env) 
    return env 
# ================================================================================ 


# ================================================================================ 
# Here, we get the name of our current SPARK Assembly JAR file name (locally). We 
# use that to create a HDFS URL that points to it's location in HDFS when using 
# YARN (i.e. when 'export MASTER=yarn-client'; we ignore it otherwise). 
# ================================================================================ 
# Remember to always upload/update your distribution's current SPARK Assembly JAR 
# to HDFS like this: 
# $ hdfs dfs -mkdir -p /user/spark/share/lib" # Only necessary to do once! 
# $ hdfs dfs -rm "/user/spark/share/lib/spark-assembly-*.jar" # Remove old version. 
# $ hdfs dfs -put ${SPARK_HOME}/assembly/lib/spark-assembly-[0-9]*.jar /user/spark/share/lib/ 
# ================================================================================ 
SPARK_JAR_LOCATION = glob.glob(SPARK_HOME + '/lib/' + 'spark-assembly-[0-9]*.jar')[0].split("/")[-1] 
SPARK_JAR_LOCATION = 'hdfs://' + namenode + ':8020/user/spark/share/lib/' + SPARK_JAR_LOCATION 
# ================================================================================ 


# ================================================================================ 
# Update Pythons globals environment variable dict with necessary environment 
# variables that the SPARK Shell will be looking for. Some we set explicitly via 
# an in-line dictionary, as shown below. And the rest are set by 'source'ing the 
# global SPARK environment file (although we could have included those explicitly 
# here too, if we preferred not to touch that system-wide file -- and leave it as FCS). 
# ================================================================================ 
spark_jar_opt = None 
MASTER = os.getenv('MASTER') if os.getenv('MASTER') else 'local[8]' 
if MASTER.startswith('yarn-'): spark_jar_opt = ' -Dspark.yarn.jar=' + SPARK_JAR_LOCATION 
elif MASTER.startswith('spark://'): pass 
else: HADOOP_HOME = '' 
# ================================================================================ 


# ================================================================================ 
# Build '--driver-java-options' options for spark-shell, pyspark, or spark-submit. 
# Many of these are set in '/etc/spark/conf/spark-defaults.conf' (and thus 
# commented out here, but left here for reference completeness). 
# ================================================================================ 
# Default UI port is 4040. The next statement allows us to run multiple SPARK shells. 
DRIVER_JAVA_OPTIONS = '-Dspark.ui.port=' + str(random.randint(1025, 65535)) 
DRIVER_JAVA_OPTIONS += spark_jar_opt if spark_jar_opt else '' 
# ================================================================================ 

# ================================================================================ 
# Build PYSPARK_SUBMIT_ARGS (i.e. the sames ones shown in 'pyspark --help'), and 
# apply them to the O/S environment. 
# ================================================================================ 
DRIVER_JAVA_OPTIONS = "'" + DRIVER_JAVA_OPTIONS + "'" 
PYSPARK_SUBMIT_ARGS = ' --master ' + MASTER # Remember to set MASTER on UNIX CLI or in the IDE! 
PYSPARK_SUBMIT_ARGS += ' --driver-java-options ' + DRIVER_JAVA_OPTIONS # Built above. 
# ================================================================================ 
os.environ.update(source('/etc/spark/conf/spark-env.sh', update = False)) 
os.environ.update({ 'PYSPARK_SUBMIT_ARGS' : PYSPARK_SUBMIT_ARGS }) 
# ================================================================================ 


# ================================================================================ 
# Next, adjust 'sys.path' so SPARK Shell has the python modules it needs. 
# ================================================================================ 
SPARK_PYTHON_DIR = SPARK_HOME + '/python' 
PY4J = glob.glob(SPARK_PYTHON_DIR + '/lib/' + 'py4j-*-src.zip')[0].split("/")[-1] 
sys.path = [SPARK_PYTHON_DIR, SPARK_PYTHON_DIR + '/lib/' + PY4J] + sys.path 
# ================================================================================ 


# ================================================================================ 
# With our environment set, we start the SPARK Shell; and then to that, we add 
# our favorite Python imports (e.g. numpy, scipy; etc). 
# ================================================================================ 
print('PYSPARK_SUBMIT_ARGS:' + PYSPARK_SUBMIT_ARGS) # For visual debug. 
execfile(SPARK_HOME + '/python/pyspark/shell.py', globals()) # Start the SPARK Shell. 
execfile(os.getenv('PYSTARTUP')) # Next, load our favorite Python modules. 
# ================================================================================ 

आनंद लें और शुभकामनाएँ!= :)

0
  1. तुम सिर्फ मॉड्यूल आयात करना चाहते हैं, अजगर पथ में जोड़ने से आप आईडीई से पूरा स्क्रिप्ट चलाना चाहते हैं तो पर्याप्त

  2. है, तो आप एक 'उपकरण' बना सकते हैं कि आईडीई (सामान्य रन के बजाय)

  3. स्पाइडर के लिए विशेष रूप से

    से अपनी स्क्रिप्ट निष्पादित करने के लिए चिंगारी से जमा कर सकते का उपयोग करता है (या अन्य आईडीई के कि अजगर लिखे गए हैं) आप के भीतर से आईडीई चला सकते हैं चिंगारी के लिये भेज

उदाहरण:

spark-submit.cmd c:\Python27\Scripts\spyder.py 
  • टिप्पणी है कि मैं स्पाइडर नाम बदलने के लिए spyder.py पड़ा - यह चिंगारी दिखाई देता है प्रस्तुत विस्तार पर निर्भर करता है अजगर, जावा, या स्केला के बीच भेद करना
  • पर किसी भी आवश्यक पैरामीटर जोड़ स्पार्क-सबमिट
2

धन्यवाद Ophir YokTon की ऊपरी पोस्ट, मैं अंत में "स्पार्क 1.4.1+ स्पाइडर 2.3.4" के साथ ऐसा करने में कामयाब रहा।

यहां मैं इसे करने के लिए अपने सभी चरणों पर एक सारांश देना चाहता हूं, उम्मीद है कि यह समान परिस्थितियों में कुछ लोगों की मदद कर सकता है।

  1. PythonPATH चर .bashrc में जोड़ें। (बेशक आप अन्य प्रासंगिक प्रोफ़ाइल फाइल में डाल सकते हैं)
export PYTHONPATH=$SPARK_HOME/python/:$PYTHONPATH 

export PYTHONPATH=$SPARK_HOME/python/lib/py4j-0.8.2.1-src.zip:$PYTHONPATH 
  1. यह प्रभावी द्वारा
source .bashrc 
बनाओ
  1. अपने स्पाइडर बिन निर्देशिका
cp spyder spyder.py 
पर spyder.py के रूप में स्पाइडर की एक प्रति बनाएं
    निम्न आदेश
spark-submit spyder.py 

मैं the sample "simple app" from apache spark लागू किया और स्पाइडर वातावरण में चल रहा है परीक्षण इसे पारित साथ

  • प्रारंभ स्पाइडर आईडीई। कृपया चित्र "http://i.stack.imgur.com/xTv6s.gif"

  • संबंधित मुद्दे