TypeError: load() missing 1 required positional argument: 'Loader' in Google Colab

TypeError: load() missing 1 required positional argument: 'Loader' in Google Colab

我正在尝试在 Google Colab 中进行常规导入。
此导入一直有效到现在。
如果我尝试:

import plotly.express as px

import pingouin as pg

我收到一个错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-86e89bd44552> in <module>()
----> 1 import plotly.express as px

9 frames
/usr/local/lib/python3.7/dist-packages/plotly/express/__init__.py in <module>()
     13     )
     14 
---> 15 from ._imshow import imshow
     16 from ._chart_types import (  # noqa: F401
     17     scatter,

/usr/local/lib/python3.7/dist-packages/plotly/express/_imshow.py in <module>()
      9 
     10 try:
---> 11     import xarray
     12 
     13     xarray_imported = True

/usr/local/lib/python3.7/dist-packages/xarray/__init__.py in <module>()
      1 import pkg_resources
      2 
----> 3 from . import testing, tutorial, ufuncs
      4 from .backends.api import (
      5     load_dataarray,

/usr/local/lib/python3.7/dist-packages/xarray/tutorial.py in <module>()
     11 import numpy as np
     12 
---> 13 from .backends.api import open_dataset as _open_dataset
     14 from .backends.rasterio_ import open_rasterio as _open_rasterio
     15 from .core.dataarray import DataArray

/usr/local/lib/python3.7/dist-packages/xarray/backends/__init__.py in <module>()
      4 formats. They should not be used directly, but rather through Dataset objects.
      5 
----> 6 from .cfgrib_ import CfGribDataStore
      7 from .common import AbstractDataStore, BackendArray, BackendEntrypoint
      8 from .file_manager import CachingFileManager, DummyFileManager, FileManager

/usr/local/lib/python3.7/dist-packages/xarray/backends/cfgrib_.py in <module>()
     14     _normalize_path,
     15 )
---> 16 from .locks import SerializableLock, ensure_lock
     17 from .store import StoreBackendEntrypoint
     18 

/usr/local/lib/python3.7/dist-packages/xarray/backends/locks.py in <module>()
     11 
     12 try:
---> 13     from dask.distributed import Lock as DistributedLock
     14 except ImportError:
     15     DistributedLock = None

/usr/local/lib/python3.7/dist-packages/dask/distributed.py in <module>()
      1 # flake8: noqa
      2 try:
----> 3     from distributed import *
      4 except ImportError:
      5     msg = (

/usr/local/lib/python3.7/dist-packages/distributed/__init__.py in <module>()
      1 from __future__ import print_function, division, absolute_import
      2 
----> 3 from . import config
      4 from dask.config import config
      5 from .actor import Actor, ActorFuture

/usr/local/lib/python3.7/dist-packages/distributed/config.py in <module>()
     18 
     19 with open(fn) as f:
---> 20     defaults = yaml.load(f)
     21 
     22 dask.config.update_defaults(defaults)

TypeError: load() missing 1 required positional argument: 'Loader'

我认为可能是Google Colab 或一些已经更新的基本实用程序包的问题,​​但我找不到解决它的方法。

找到问题了。
我正在安装 pandas_profiling,此软件包已更新 pyyaml 至 6.0 版,这与 Google Colab 导入软件包的当前方式不兼容。
所以只需恢复到 pyyaml 版本 5.4.1 即可解决问题。

有关更多信息,请检查 pyyaml here.
的版本 在 GitHub

中查看此问题和正式答案

############################################# #####################
要在代码中恢复到 pyyaml 版本 5.4.1,请在软件包安装的末尾添加下一行:

!pip install pyyaml==5.4.1

把它放在安装的最后很重要,有些安装会改变pyyaml版本。

现在,load() 函数需要参数 loader=Loader

如果您的 YAML 文件仅包含简单的 YAML(str、int、列表),请尝试使用 yaml.safe_load() 而不是 yaml.load()。 如果你需要 FullLoader,你可以使用 yaml.full_load().

从pyyaml>=5.4开始,没有发现严重漏洞,pyyaml status.

来源:

yaml.safe_load() should always be preferred unless you explicitly need the arbitrary object serialization/deserialization provided in order to avoid introducing the possibility for arbitrary code execution.

更多关于 yaml.load(input) here

解决 TypeError: load() missing 1 required positional argument: 'Loader' 错误 这里的错误是提到你的 load() 函数需要 param loader=Loader。所以你需要使用 safe_load() 而不是 load()。第二种解决方案是 Here pyyaml latest version 6.0 is not compatible with the current way Google Colab imports packages。因此,只需将 pyyaml 版本降级到 5.4.1,它与 Google Colab 导入的当前方式兼容,它将解决您的错误。使用此命令降级pyyaml 当我加载 texthero 包时,我在重新启动 google colab i 后安装 pyyaml 版本 5.4.1 后出现此错误 纠正错误

答案:- !pip install pyyaml==5.4.1