You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Jupyter Lab中导入PySpark的VectorAssembler时出现ModuleNotFoundError

解决PySpark中VectorAssembler导入失败的ModuleNotFoundError

问题重现

运行以下导入语句:

from pyspark.ml.feature import VectorAssembler

触发ModuleNotFoundError,完整错误回溯如下:

ModuleNotFoundError                       Traceback (most recent call last)
Cell In[5], line 1
----> 1 from pyspark.ml.feature import VectorAssembler

File /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pyspark/ml/__init__.py:22
      1 #
      2 # Licensed to the Apache Software Foundation (ASF) under one or more
      3 # contributor license agreements.  See the NOTICE file distributed with
   (...)
     15 # limitations under the License.
     16 #
     18 """
     19 DataFrame-based machine learning APIs to let users quickly assemble and configure practical
     20 machine learning pipelines.
     21 """

解决方案

  • 重新安装PySpark确保完整性
    从错误路径来看,PySpark的基础ml模块存在但无法加载子模块,大概率是安装不完整导致。执行以下命令重装:

    pip uninstall -y pyspark
    pip install pyspark
    
  • 切换兼容的Python版本
    当前使用的Python 3.13属于较新版本,PySpark对其支持可能存在延迟。建议切换到PySpark官方明确支持的版本(如Python 3.8~3.12),再重新安装测试。

  • 配置正确的PySpark环境变量
    确保PYSPARK_PYTHON环境变量指向目标Python解释器,避免版本冲突:

    export PYSPARK_PYTHON=/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12
    

    (替换为你实际使用的兼容版本Python路径)

  • 检查虚拟环境有效性
    如果使用虚拟环境运行代码,确认环境已激活,且PySpark是安装在当前虚拟环境内,而非全局Python环境。

内容的提问来源于stack exchange,提问作者Trango

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 23:39:51