- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 pyspark 读取一些 csv 数据以触发 Dataframe。
我尝试按如下方式导入 pyspark 模块:
from pyspark.sql import sqlContext
为什么我会收到以下错误?如何解决?
ImportError: cannot import name sqlContext
我使用的是 Python 2.7 和 Spark 2.0.1
最佳答案
这可能是因为你的 python pat 设置不正确。我发现以下函数在配置 python 环境时很有用。
def configure_spark(spark_home=None, pyspark_python=None, conf_dir=None):
"""Configures the Python path for importing pyspark
Sets the SPARK_HOME and PYSPARK_PYTHON environment variables and modifies
the Python PATH so the pyspark package can be imported.
Args:
spark_home (str): Path of SPARK_HOME. Defaults to SPARK_HOME module
variable.
pyspark_python (str): Path to Python binary to use in PySpark. Defaults
to the currently executing Python binary.
conf_dir (str): Path to configuration directory
"""
# Set the configuration directory with some basic sanity checks:
if conf_dir:
if not os.path.isdir(conf_dir):
raise OSError("Spark config directory not found: %s" % conf_dir)
expected_conf = {'spark-env.sh', 'spark-defaults.conf'}
found_conf = expected_conf - set(os.listdir(conf_dir))
if found_conf:
warnings.warn("Some configuration files were not found: %s" % found_conf)
os.environ['SPARK_CONF_DIR'] = conf_dir
spark_home = spark_home or SPARK_HOME
os.environ['SPARK_HOME'] = spark_home
if not os.path.isdir(spark_home):
raise OSError("Specified SPARK_HOME is not a valid directory: %s" % spark_home)
# Add the PySpark directories to the Python path:
libs = glob(os.path.join(spark_home, 'python', 'lib', '*.zip'))
if len(libs) < 2:
raise OSError("Pyspark libraries not found in %s" % spark_home)
for lib in libs:
sys.path.insert(1, lib)
# If PYSPARK_PYTHON isn't specified, use currently running Python binary:
pyspark_python = pyspark_python or sys.executable
os.environ['PYSPARK_PYTHON'] = pyspark_python
关于python - 导入错误:无法导入名称 sqlContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41132439/
为什么在 Scala Spark 应用程序中初始化 SQLContext 后导入隐式 SqlContext.implicits._。 当 import 放在 object 之外时,似乎有问题。 我来自
我只是想将文本文件读入 pyspark RDD,我注意到 sqlContext.read.load 之间的巨大差异和 sqlContext.read.text . s3_single_file_inp
我正在使用 Spark Dataframe API 从 NFS 共享加载/读取文件,然后将该文件的数据保存/写入 HDFS。 我有一个包含一个主节点和两个工作节点的三节点 Spark 集群。我的 Sp
我是Spark环境的新手,正在尝试将CSV文件导入Spark 2.0.2。我正在Windows 10上使用pyspark。这是到目前为止的代码 from pyspark.sql.types
我正在学习 Spark 和斯卡拉。我精通java,但对scala不太了解。我正在阅读有关 spark 的教程,并遇到了以下代码行,尚未解释: val sqlContext = new org.apac
我的代码正在从 sqlcontext 中读取数据。该表中有 2000 万条记录。我想计算表中的 totalCount。 val finalresult = sqlContext.sql(“SELECT
我正在使用 pyspark 读取一些 csv 数据以触发 Dataframe。 我尝试按如下方式导入 pyspark 模块: from pyspark.sql import sqlContext 为什
我有一个笔记本 a.pynb,它具有读取 parquet 文件语句的功能。 我在另一个笔记本 b.pynb 中使用 a.pynb,在这个新笔记本中,我调用 a.pynb 的一个函数来读取这个 parq
此代码从给定列表创建数据框: sample_one = [(0, 'mouse'), (1, 'black')] sample_two = [(0, 'cat'), (1, 'tabby'), (2,
我有一个数据框,我想将数据汇总到 7 天内并对某些函数进行一些聚合。 我有一个 pyspark sql 数据框,比如 ------ Sale_Date|P_1|P_2|P_3|G_1|G_2|G_3|
我尝试通过一个简单的 Spark 作业(用 Java 编写)查询 Hive 表。 SparkConf conf = new SparkConf().setMaster("local[*]").setA
我正在尝试在 zeppelin 中使用 sqlContext.jsonFile 访问一些 json 数据... 以下代码执行没有任何错误: import sys.process._ val sqlCo
我的文件中只有 3 个事件(第 3 列)01、02、03。 模式是 unixTimestamp|id|eventType|date1|date2|date3 639393604950|1001|01|
我是新来的 Spark 。我只是想使用 sparksession 或 sqlcontext 解析一个 json 文件。 但是每当我运行它们时,我都会收到以下错误。 Exception in threa
我在 Spark 中使用了 SQL,在这个例子中: results = spark.sql("select * from ventas") 其中ventas是一个数据框,以前像表格一样编目: df.c
运行简单的Spark程序,尝试从HDFS读取CSV时出现NoSuchMethodError。 错误: Exception in thread "main" java.lang.NoSuchMethod
我已经导入了以下模块。我尝试从 sqlCtx.read.format 加载数据,但出现 "IllegalArgumentException: u"Error while instantiating '
我有一个名为 getAge(timestamp:Long) 的方法,我想将其注册为 sql 函数。 我有 sqlContext.udf.register("getAge",getAge) 但它告诉我我
我在具有以下签名的 Scala 对象中有一个函数 def f(v1:Int)(implicit sqlContext: SQLContext) 当我尝试从 spark-shell 调用这个函数时,我这
为了进行比较,假设我们有一个表“T”,其中包含两列“A”、“B”。我们还有一个在一些 HDFS 数据库中运行的 hiveContext。我们制作一个数据框: 理论上,以下哪个更快: sqlContex
我是一名优秀的程序员,十分优秀!