Integrate Apache Spark with latest IPython Notebook (Jupyter 4.x)

Ubuntu24.04 Miniconda+JupyterHub 局域网多用户严格权限部署最终方案 本文提出Ubuntu 24.04下Miniconda+JupyterHub多用户严格权限部署的零漏洞方案,彻底解决原方案中系统权限破坏、绕过安全限制等缺陷。通过固定路径安装Miniconda(/opt/miniconda3)、全局只读权限控制、禁止用户本地登录与命令执行、禁用Jupyter终端及魔法命令、隔离用户文件与环境,并实现开机自启、资源限制与内核白名单管理,确保企业级安全稳定运行,满足局域网多用户协作需求。 阅读详情

Posted on December 24, 2015 | Topics:python, spark , ipython , jupyter , spark-redshift

As you may already know, Apache Spark is possibly the most popular engine right now for large-scale data processing, while IPython Notebook is a prominent front-end for, among other things, sharable exploratory data analysis. However, getting them to work with each other requires some additional step, especially since latest IPython Notebook has been moved under the Jupyter umbrella and doesn’t support profile anymore.

Table of Contents

  • I. Prerequisites
  • II. PySpark with IPython Shell
  • III. PySpark with Jupyter Notebook
  • IV. Bonus: Spark Redshift

I. Prerequisites

This setup has been tested with the following software:

  • Apache Spark 1.5.x
  • IPython 4.0.x (the interactive IPython shell & a kernel for Jupyter)
  • Jupyter 4.0.x (a web notebook on top of IPython kernel)
$ pyspark --version
$ ipython --version
$ jupyter --version

You will need to set an environment variable as follows:

  • SPARK_HOME : this is where the spark executables reside. For example, if you are on OSX and install Spark via homebrew, add this to your .bashrc or whatever.rc you use. This path differs between environment and installation, so if you don’t know where it is, Google is your friend.
$ echo "export SPARK_HOME='/usr/local/Cellar/apache-spark/1.5.2/libexec/'" >> ~/.bashrc

II. PySpark with IPython Shell

The following is adapted from Cloudera . I have removed some unnecessary steps if you just want to get up and running very quickly.

1. Step 1: Create an ipython profile
$ ipython profile create pyspark

# Possible outputs
# [ProfileCreate] Generating default config file: u'/Users/lim/.ipython/profile_spark/ipython_config.py'
# [ProfileCreate] Generating default config file: u'/Users/lim/.ipython/profile_spark/ipython_kernel_config.py'
2. Step 2: Create a startup file for this profile

The goal is to have a startup file for this profile so that everytime you launch an IPython interactive shell session, it loads the spark context for you.

$ touch ~/.ipython/profile_spark/startup/00-spark-setup.py

A minimal working version of this file is

import os
import sys

spark_home = os.environ.get('SPARK_HOME', None)
sys.path.insert(0, os.path.join(spark_home, 'python'))
sys.path.insert(0, os.path.join(spark_home, 'python/lib/py4j-0.8.2.1-src.zip'))
execfile(os.path.join(spark_home, 'python/pyspark/shell.py'))

Verify that this works

$ ipython --profile=spark

You should see a welcome screen similar to this with the SparkContext object pre-created

Fig. 1 | Spark welcome screen

III. PySpark with Jupyter Notebook

After getting spark to work with IPython interactive shell, the next step is to get it to work with the Jupyter Notebook. Unfortunately, since the big split , Jupyter Notebook doesn’t support IPython profile out of the box anymore. To reuse the profile we created earlier, we are going to provide a modified IPython kernel for any spark-related notebook. The strategy is described here but it has some unnecessary boilerplates/outdated information, so here is an improved version:

1. Preparing the kernel spec

IPython kernel specs reside in ~/.ipython/kernels , so let’s create a spec for spark:

$ mkdir -p ~/.ipython/kernels/spark
$ touch ~/.ipython/kernels/spark/kernel.json

with the following content:

{
    "display_name": "PySpark (Spark 1.5.2)",
    "language": "python",
    "argv": [
        "/usr/bin/python2",
        "-m",
        "ipykernel",
        "--profile=spark"
        "-f",
        "{connection_file}"
    ]
}

Some notes: If you are using a virtual environment, change the python entry point to your virtualenvironment’s, e.g. mine is ~/.virtualenvs/machine-learning/bin/python

2. Profit

Now simply launch the notebook with

$ jupyter notebook
# ipython notebook works too

When creating a new notebook, select the PySpark kernel and go wild :)

Fig. 2 | Select PySpark kernel for a new Jupyter Notebook
Fig. 3 | Example of spark interacting with matplotlib

IV. Bonus: Spark-Redshift

Amazon Redshift is a popular choice for Data Warehousing and Analytics Database. Now you can easily load data from your Redshfit cluster into Spark’s native DataFrame using a spark package called Spark-Redshift . To hook it up with our jupyter notebook setup, add this to the kernel file

{
    ...
    "env": {
        "PYSPARK_SUBMIT_ARGS": "--jars </path/to/redshift/jdbc.jar> --packages com.databricks:spark-redshift_2.10:0.5.2,com.amazonaws:aws-java-sdk-pom:1.10.34,org.apache.hadoop:hadoop-aws:2.6.0 pyspark-shell"
    }
    ...
}

Please note that you need a JDBC drive for Redshfit, which can be downloadedhere . The last tricky thing to note is that the package uses Amazon S3 as the transportation medium, so you will need to configure the spark context object with your AWS credentials. This could be done on top of your notebook with:

sc._jsc.hadoopConfiguration().set("fs.s3n.awsAccessKeyId", "YOUR_KEY_ID")
sc._jsc.hadoopConfiguration().set("fs.s3n.awsSecretAccessKey", "YOUR_SECRET_ACCESS_KEY")

Whew! I admit it’s a bit long but totally worth the trouble. Spark + IPython on top of Redshift is a very formidable combination for exploring your data at scale.

金澜涛-Managing Apache Spark Workload and Automatic Optimizing-脱敏.pdf Apache Spark Work 立即下载

相关推荐

Win11上WSL2安装Ubuntu22.04避坑指南:从镜像源到C++环境配置

本文详细介绍了在Win11系统上安装和配置WSL2及Ubuntu22.04开发环境的完整流程与避坑指南。内容涵盖从解决网络安装错误、更换国内镜像源以加速软件更新,到一站式配置C++开发工具链(包括GCC、GDB、CMake等),并提供了提升WSL2使用体验的实用技巧和故障排除方法,帮助开发者高效搭建稳定的Linux开发环境。

weixin_29306261的博客 474

Python数据科学入门-笔记01

Python数据科学入门 慕课网课程学习笔记 学习环境 win10 + 虚拟机centos7 + python3 第一节 Annconda 基本介绍 一、Anaconda 介绍 1.Anaconda 介绍 Anaconda /,ænə’kɑndə/ Anaconda 是最著名的Python数据科学平台,750+ 流行的Python&amp;amp;R包 跨平台,开源,...

zranfly 2978

LFM调制信号分类与检测识别

支持识别LFM信号、间歇采样干扰(ISRJ)、灵巧噪声干扰(SNJ)、扫频干扰(SJ)、瞄准干扰(AJ)、阻塞干扰(BJ)、密集假目标干扰(DFJ)、密集假目标加灵巧噪声干扰(DFWSNJ)、距离欺骗干扰(DDJ)、距离欺骗加灵巧噪声干扰(DDWSNJ)。Faster-RCNN支持检测识别LFM信号、间歇采样干扰(ISRJ)、灵巧噪声干扰(SNJ)、扫频干扰(SJ)、瞄准干扰(AJ)、密集假目标干扰(DFJ)、密集假目标加灵巧噪声干扰(DFWSNJ)、距离欺骗加灵巧噪声干扰(DDWSNJ)等8种信号。

菜yuan~的博客 1029

【python】警告

一、1、想合并两列数据,采用append或者concat函数,均会出现以下警告内容:FutureWarning:Sorting because n on-concatenation axis is not aligned. A future version of pandas will change to not sort by default. To accept the future behavior , pass ’ sort = False ’ . To retain the current beh

qq_40855100的博客 3895

SpringBoot整合oceanbase,实现oracle无缝切换到oceanbase

随着去“IOE”化的潮流,近些年来,许多与国家相关的项目不约而同到地往”国产化“方向靠拢,不可避免地,一些项目可能需要进行数据库迁移。

4622

告别单一帧:在CFD-POST中完整加载Fluent瞬态计算结果的实战指南

本文详细介绍了在CFD-POST中完整加载Fluent瞬态计算结果的实战指南,解决工程师常见的只能看到最后一帧数据的问题。通过Fluent端的正确设置和CFD-POST端的完整加载技巧,帮助用户高效处理瞬态数据,提升后处理效率。文章还提供了常见问题排查、性能优化和高级后处理技巧,适用于Workbench环境下的流体流动分析。

weixin_29284657的博客 537

pyspark设置Hadoop参数

sc._jsc.hadoopConfiguration().set('my.mapreduce.setting', 'someVal') 注意一个细节也不要放过 链接来源:https://www.it1352.com/1934092.html

BiuFEIMIR的博客 1008

《BiLSTM with Multi-Polarity Orthogonal Attention for Implicit Sentiment Analysis》论文阅读笔记

文章名:《BiLSTM with Multi-Polarity Orthogonal Attention for Implicit Sentiment Analysis》 作者Jiyao Wei a,1, Jian Liaoa,1, Zhenfei Yanga, Suge Wanga,b,∗, Qiang Zhaoa 年份 2019 1 Introduction 目前文本情感分析多分析带...

weixin_39036944的博客 1630

ROS节点无法读入launch参数问题

总述 由于没有注意 参数 与 句柄的 全局/局部 关系,从而使得launch文件的参数无法正常进入节点中。 表现 问题代码来自 https://github.com/RuPingCen/publish_pointcloud launch文件。 <launch> <node name="publish_pointcloud" pkg="publish_pointcloud" type="publish_pointcloud" output="screen"> <param

shuang_yu_的博客 1712

OnlyOffice Docker部署踩坑实录:解决Nginx反向代理导致的editor.bin下载失败

本文详细解析了在Docker中部署OnlyOffice时,因Nginx反向代理配置不当导致editor.bin下载失败的常见问题。通过分析问题根源,提供了从Nginx代理配置、Docker网络设置到OnlyOffice容器内部调整的完整解决方案,并分享了实战调试技巧与性能优化建议,帮助用户彻底解决这一部署难题。

wine的专栏 523

第十六章:载板制造工艺大全

本文详细介绍了IC载板制造的完整工艺流程,主要包括开料、钻孔、孔金属化、图形形成、层压、表面处理、成型和电测8大工序。每个工序都列出了关键参数和质量控制要点,如开料尺寸精度±0.1mm、激光钻孔孔径50-150μm、孔金属化铜厚20-30μm、图形形成线宽15μm±2μm等。文中还特别说明了MSAP工艺和沉金等特殊工艺的详细流程,以及成型精度和电测标准等关键指标。全文通过流程图和参数表格直观展示了IC载板制造的核心工艺和质量要求。

Open 184

基于 Native 技术加速 Spark 计算引擎

今天分享的主题是基于 Native 技术加速 Spark 计算引擎,大家将会了解到如何基于 ClickHouse 来改造 Spark 引擎,最终获得较为可观的性能提升。

lihui49的博客 1036

YOLO11改进-注意力-引入多尺度注意力聚合(MSAA)模块

对来自backbone的特征进行细化处理。通过空间和通道两个路径的操作,增强了空间和通道方面的特征信息,使得输出的特征图在空间和通道维度上都更加优质。1. 在空间细化路径中,通过对不同核大小的卷积进行求和以及一系列的空间特征聚合操作,实现了多尺度空间信息的融合。2. 在通道聚合路径中,通过全局平均池化、卷积和激活等操作生成通道注意力图,并与空间细化后的图相结合,实现了通道维度上的多尺度信息融合。

qq_64693987的博客 4675

Jupyter配置Spark开发环境

兄弟连大数据培训(www.lampbrother.net )和大家一起探究Jupyter配置 Spark 开发环境 简介   为Jupyter配置Spark开发环境,可以安装全家桶–Spark Kernel或Toree,也可按需安装相关组件。   考虑到一般人更喜欢一步到位,并且Toree将会代替Spark Kernel,故直接且仅需安装Toree即可,不过下面还是...

iteye_4242的博客 214

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

python中int 3.14_警告:在Scipy 1.14.3中不推荐使用imresize

我收到以下警告信息:...\anaconda3\lib\site-packages\ipykernel_launcher.py:1:DeprecationWarning: `imresize` is deprecated!`imresize` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.Use ``skimage.trans...

weixin_39878698的博客 653

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

pandas数据分析给力教程【完整版】(五)

pandas的拼接操作 pandas的拼接分为两种: 级联:pd.concat, pd.append 合并:pd.merge import numpy as np import pandas as pd from pandas import Series, DataFrame import matplotlib.pyplot as plt 0. 回顾numpy的级联 ============================================ 练习12: 生成2个3*3的矩阵,对其分别进

zly717216的博客 6628

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Python-pandas-多层索引

多层索引可以切片,但是: 1.外层标签必须是经过排序的; 2.每个索引的外层标签第一个字母必须得一致,要么全是大写,要么全是小写 Series_123=pd.Series(np.random.randint(10),index=[['apple','apple','apple','apricot','apricot','apricot','banana','banana','blackber

baidu_38409988的博客 9011

python执行mongo命令_使用Python操作mongodb数据库

安装MongoDB启动mongodb服务命令:mongod --dbpath C:\software\mongodb\data\db其中, dbpath 后面的参数是安装的 mongodb 下面创建的目录路径连接MongoDB安装 pymongo 库pip3 install pymongoimport pymongoclient = pymongo.MongoClient(host='localh...

weixin_36184307的博客 636

spyder中ipython报kernel deid ,Restart kernel解决办法

如题:spyder中ipython报kernel deid ,Restart kernel解决办法 碰到过好多次,猜测应该是删除了某个支持的库的问题; 第一个方法:把刚才卸载的库安装上去,如我卸载了tornado之后报错,重新安装上去就变正常了; 第二个方法:卸载重新安装spyder;

云金杞 2万+

数据基础---《利用Python进行数据分析·第2版》第8章 数据规整:聚合、合并和重塑

之前自己对于numpy和pandas是要用的时候东学一点西一点,直到看到《利用Python进行数据分析·第2版》,觉得只看这一篇就够了。非常感谢原博主的翻译和分享。 ...

1950

关于Pandas中的部分索引技巧

关于Pandas中的部分索引技巧import pandas as pd .loc .iloc

sosososj的博客 1153

kaggle Home Depot relevance相关性预测

Home Depot 产品相关性预测 kaggle竞赛:https://www.kaggle.com/c/home-depot-product-search-relevance HomeDepot是美国一家家具建材商品网站,用户通过在搜索框中输入关键词,得到相关商品和服务,如输入floor,得到不同材料的地板商品、地板清洗商品、地板安装服务等。kaggle竞赛目的是通过设计一种模型,能够更好的...

iam_emily的博客 3068

利用python进入数据分析之数据规整化:清理、转换、合并、重塑(二)

数据转换 移除重复数据 In [106]: data = DataFrame({'k1': ['one'] * 3 + ['two'] * 4, 'k2': [1, 1, 2, 3, 3, 4, 4]}) data Out[106]:

若云流风的专栏 3194

数据分析Task01

初次参加,记录一下学习过程,熟悉datawhale小组规则和blog。 没有学习过python数据分析,第一天的课程简单,查资料照着敲基本不会有问题,重在理解库函数的功能,为后面打基础。 容易出错的地方:读取数据用绝对目录时,“\”写反会导致编码类的报错(windows里复制目录相反,记住和浏览器地址斜杠一致即可)。 关于jupyter,如果默认路径不是当前文件下,需要upload导入。 第一章:数据加载 导入numpy,pandas 载入数据数据集和ipynb同一目录下 import nu

yabastone的博客 315

详解 jupyter notebook 集成 spark 环境安装

来自: 代码大湿 代码大湿 1 相关介绍 jupyter notebook是一个Web应用程序,允许你创建和分享,包含活的代码,方程的文件,可视化和解释性文字。用途包括:数据的清洗和转换、数值模拟、统计建模、机器学习和更多。支持40多中语言。python ,R,go,scala等。 Spark是UC Berkeley AMP lab所开源的类Hadoop MapReduce的通用并...

weixin_33794672的博客 909
上一篇: 4.机器学习实战之朴素贝叶斯
下一篇: 纯JS回显form各种表单数据
Wang_AI
博客等级 码龄12年 988粉丝 162原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值