I want to load IPython shell (not IPython notebook) in which I can use PySpark through command line. Is that possible? I have installed Spark-1.4.1.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to maintain order of key-value in DataFrame sa
- How to get the background from multiple images by
- Evil ctypes hack in python
What I found to be helpful is to write bash scripts that load Spark in a specific way. Doing this will give you an easy way to start Spark in different environments (for example ipython and a jupyter notebook).
To do this open a blank script (using whatever text editor you prefer), for example one called
ipython_spark.sh
For this example I will provide the script I use to open spark with the ipython interpreter:
Note that I have SPARK_HOME defined in my bash_profile, but you could just insert the whole path to wherever pyspark is located on your computer
I like to put all scripts like this in one place so I put this file in a folder called "scripts"
Now for this example you need to go to your bash_profile and enter the following lines:
These paths will be specific to where you put ipython_spark.sh and then you might need to update permissions:
and source your bash_profile:
I'm on a mac, but this should all work for linux as well, although you will be updating .bashrc instead of bash_profile most likely.
What I like about this method is that you can write up multiple scripts, with different configurations and open spark accordingly. Depending on if you are setting up a cluster, need to load different packages, or change the number of cores spark has at it's disposal, etc. you can either update this script, or make new ones. As noted by @zero323 above PYSPARK_DRIVER_PYTHON= is the correct syntax for Spark > 1.2 I am using Spark 2.2
None of the mentioned answers worked for me. I always got the error:
What I did was launching
ipython
and creating Spark session manually:To avoid doing this every time, I moved the code to
~/.ispark.py
and created the following alias (add this to~/.bashrc
):After that, you can launch PySpark with iPython by typing:
According to the official Github, IPYTHON=1 is not available in Spark 2.0+ Please use PYSPARK_PYTHON and PYSPARK_DRIVER_PYTHON instead.
https://github.com/apache/spark/blob/master/bin/pyspark
I use ptpython(1), which not only supplies ipython functionality as well as your choice of either vi(1) or emacs(1) key-bindings; it also supplies dynamic code pop-up sense/intelligence, which is extremely useful when doing Ad-Hoc SPARK work on the CLI.
Here is what my vi-enabled ptpython session looks like, taking note of the VI (INSERT) mode at the bottom of the screehshot, as well as the ipython style prompt to indicate that those ptpython capabilities have been selected (more on how to select them in a moment):
To get all of this, perform the following simple steps:
To select your pypython preferences (and there are a bunch of them), simply press F2 from within a ptpython session, and select whatever options you want.
CLOSING NOTE: If you are submitting a Python Spark Application (as opposed to interacting with pyspark(1) via the CLI, as shown above), simply set PYSPARK_PYTHON and PYSPARK_DRIVER_PYTHON programmatically in Python, like so:
I hope this answer and setup useful.
Here is what worked for me:
and then from the SPARK_HOME directory:
if version of spark >= 2.0 and the follow config could be adding to .bashrc