【问题标题】:"TypeError: an integer is required (got type bytes)" when importing pyspark on Python 3.8 [duplicate]在 Python 3.8 上导入 pyspark 时,“TypeError:需要一个整数(获取类型字节)”[重复]
【发布时间】:2020-06-01 16:22:21
【问题描述】:
  1. 创建了一个 conda 环境:
conda create -y -n py38 python=3.8
conda activate py38
  1. 从 Pip 安装 Spark:
pip install pyspark
# Successfully installed py4j-0.10.7 pyspark-2.4.5
  1. 尝试导入 pyspark:
python -c "import pyspark"

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/dmitrii_deriabin/anaconda3/envs/py38/lib/python3.8/site-packages/pyspark/__init__.py", line 51, in <module>
    from pyspark.context import SparkContext
  File "/Users/dmitrii_deriabin/anaconda3/envs/py38/lib/python3.8/site-packages/pyspark/context.py", line 31, in <module>
    from pyspark import accumulators
  File "/Users/dmitrii_deriabin/anaconda3/envs/py38/lib/python3.8/site-packages/pyspark/accumulators.py", line 97, in <module>
    from pyspark.serializers import read_int, PickleSerializer
  File "/Users/dmitrii_deriabin/anaconda3/envs/py38/lib/python3.8/site-packages/pyspark/serializers.py", line 72, in <module>
    from pyspark import cloudpickle
  File "/Users/dmitrii_deriabin/anaconda3/envs/py38/lib/python3.8/site-packages/pyspark/cloudpickle.py", line 145, in <module>
    _cell_set_template_code = _make_cell_set_template_code()
  File "/Users/dmitrii_deriabin/anaconda3/envs/py38/lib/python3.8/site-packages/pyspark/cloudpickle.py", line 126, in _make_cell_set_template_code
    return types.CodeType(
TypeError: an integer is required (got type bytes)


似乎 Pyspark 附带了 cloudpickle 包的预打包版本,在 Python 3.8 上存在一些问题,现在在 pip 版本上已解决(至少从版本 1.3.0 开始),但是 Pyspark 版本仍然损坏.有没有人遇到过同样的问题/有幸解决了这个问题?

【问题讨论】:

标签: apache-spark pyspark python-3.8


【解决方案1】:

你必须将你的 python 版本从 3.8 降级到 3.7,因为 pyspark 不支持这个版本的 python。

【讨论】:

  • 有没有办法将 aws emr 集群降级到 3.7?这方面的文档似乎只是指向 python 3.4 -> 3.6 转换...
  • 可以确认这是我的问题,python 3.8 失败,python 3.7.8 工作。
  • 不适用于 python 3.8 需要安装 3.7
  • 它不适用于python3.9,但适用于python3.7。
【解决方案2】:

我刚刚确认 (2020-11-04) 升级到 pyspark==3.0.1 可以解决问题。

【讨论】:

    【解决方案3】:

    最新的开发包应该可以解决这个问题:

    pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
    

    对话:https://github.com/pyinstaller/pyinstaller/issues/4265#issuecomment-546221741

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-20
      • 1970-01-01
      • 2020-03-01
      相关资源
      最近更新 更多