【问题标题】:How should I integrate Jupyter notebook and pyspark on Ubuntu 12.04?我应该如何在 Ubuntu 12.04 上集成 Jupyter notebook 和 pyspark?
【发布时间】:2016-08-17 19:10:35
【问题描述】:

我是 Pyspark 的新手。我在 ubuntu 上安装了“bash Anaconda2-4.0.0-Linux-x86_64.sh”。还安装了pyspark。终端中的一切工作正常。我想在jupyter上工作。当我在我的 ubuntu 终端中创建配置文件时,如下所示:

wanderer@wanderer-VirtualBox:~$ ipython profile create pyspark
[ProfileCreate] Generating default config file: u'/home/wanderer/.ipython/profile_pyspark/ipython_config.py'
[ProfileCreate] Generating default config file: u'/home/wanderer/.ipython/profile_pyspark/ipython_kernel_config.py'

wanderer@wanderer-VirtualBox:~$ export ANACONDA_ROOT=~/anaconda2
wanderer@wanderer-VirtualBox:~$ export PYSPARK_DRIVER_PYTHON=$ANACONDA_ROOT/bin/ipython
wanderer@wanderer-VirtualBox:~$ export PYSPARK_PYTHON=$ANACONDA_ROOT/bin/python

wanderer@wanderer-VirtualBox:~$ cd spark-1.5.2-bin-hadoop2.6/
wanderer@wanderer-VirtualBox:~/spark-1.5.2-bin-hadoop2.6$ PYTHON_OPTS=”notebook” ./bin/pyspark
Python 2.7.11 |Anaconda 4.0.0 (64-bit)| (default, Dec  6 2015, 18:08:32) 
Type "copyright", "credits" or "license" for more information.

IPython 4.1.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
16/04/24 15:27:42 INFO SparkContext: Running Spark version 1.5.2
16/04/24 15:27:43 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

16/04/24 15:27:53 INFO BlockManagerMasterEndpoint: Registering block manager localhost:33514 with 530.3 MB RAM, BlockManagerId(driver, localhost, 33514)
16/04/24 15:27:53 INFO BlockManagerMaster: Registered BlockManager
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /__ / .__/\_,_/_/ /_/\_\   version 1.5.2
      /_/

Using Python version 2.7.11 (default, Dec  6 2015 18:08:32)
SparkContext available as sc, HiveContext available as sqlContext.

In [1]: sc
Out[1]: <pyspark.context.SparkContext at 0x7fc96cc6fd10>

In [2]: print sc.version
1.5.2

In [3]: 

以下是jupyter和ipython的版本

wanderer@wanderer-VirtualBox:~$ jupyter --version
4.1.0

wanderer@wanderer-VirtualBox:~$ ipython --version
4.1.2

我尝试将 jupyter notebook 和 pyspark 集成,但一切都失败了。我想在 jupyter 中锻炼,不知道如何集成 jupyter notebook 和 pyspark。

谁能展示如何集成上述组件?

【问题讨论】:

  • @AlbertoBonsanto ...太好了...终于解决了问题并开始在pyspark上练习。给定的链接清除了我的障碍。!!!

标签: apache-spark ipython pyspark jupyter jupyter-notebook


【解决方案1】:

只需运行命令:

PYSPARK_DRIVER_PYTHON="jupyter" PYSPARK_DRIVER_PYTHON_OPTS="notebook" pyspark

【讨论】:

    【解决方案2】:

    使用 nano 或 vim 将两行添加到 pyspark:

    PYSPARK_DRIVER_PYTHON="jupyter"
    PYSPARK_DRIVER_PYTHON_OPTS="notebook"
    

    【讨论】:

      【解决方案3】:

      编辑 2017 年 10 月

      使用 Spark 2.2 findspark 效果很好,不需要那些环境变量

      import findspark
      findspark.init('/opt/spark')
      import pyspark
      sc = pyspark.SparkContext()
      

      我发现最快的方法是运行:

      export PYSPARK_DRIVER=ipython
      export PYSPARK_DRIVER_PYTHON_OPTS="notebook"
      pyspark
      

      或等效于 jupyter。这应该会打开一个启用了 pyspark 的 ipython 笔记本。您可能还想查看Beaker notebook

      【讨论】:

      • 更简单,在命令行中运行:IPYTHON_OPTS="notebook" $SPARK_HOME/bin/pyspark。找到here
      • IPYTHON_OPTS="notebook" $SPARK_HOME/bin/pyspark 似乎已在 Spark 2.0+ 中删除
      猜你喜欢
      • 1970-01-01
      • 2021-03-28
      • 2021-11-23
      • 1970-01-01
      • 2018-09-26
      • 1970-01-01
      • 2020-07-23
      • 2019-01-07
      • 1970-01-01
      相关资源
      最近更新 更多