首页 > 解决方案 > 如何让 VSCode 将 Python3 识别为我的默认值

问题描述

我在我的 Mac 上安装了 python3,我在终端中,我默认使用 python3。但是,当我在 VSCode 中时,它没有将 python3 识别为我的默认值,它仍在使用 python2.7。

这是我的 VScode 环境的屏幕截图:我选择了 python3 的代码运行器以及我的解释器为 3.8

在此处输入图像描述

当我运行我的代码时,我得到了这个恼人的错误:

Exception: Python in worker has different version 2.7 than that in driver 3.8, PySpark cannot run with different minor versions. Please check environment variables PYSPARK_PYTHON and PYSPARK_DRIVER_PYTHON are correctly set.

我必须打电话export PYSPARK_PYTHON=python3让我的代码运行,但我已经在我的 bash.profile 中内置了它。

为了让它正常运行,我缺少什么?

标签: pythonpython-3.xvisual-studio-codepyspark

解决方案


除非您从终端窗口运行代码,否则不清楚为什么要导出内容。您的终端未连接到 vscode 设置。

如果要应用该环境,则需要从 vscode 实际运行脚本


推荐阅读