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

Each Answer to this Q is separated by one/two green lines.

I am trying to do a regular import in Google Colab.
This import worked up until now.
If I try:

import plotly.express as px

or

import pingouin as pg

I get an error:

---------------------------------------------------------------------------
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'

I think it might be a problem with Google Colab or some basic utility package that has been updated, but I can not find a way to solve it.

Now, the load() function requires parameter loader=Loader.

If your YAML file contains just simple YAML (str, int, lists), try to use yaml.safe_load() instead of yaml.load().
And If you need FullLoader, you can use yaml.full_load().

Starting from pyyaml>=5.4, it doesn’t have any discovered critical vulnerabilities, pyyaml status.

source: https://stackoverflow.com/a/1774043/13755823

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.

More about yaml.load(input) here.

Found the problem.
I was installing pandas_profiling, and this package updated pyyaml to version 6.0 which is not compatible with the current way Google Colab imports packages.
So just reverting back to pyyaml version 5.4.1 solved the problem.

For more information check versions of pyyaml here.
See this issue and formal answers in GitHub

##################################################################
For reverting back to pyyaml version 5.4.1 in your code, add the next line at the end of your packages installations:

!pip install pyyaml==5.4.1

It is important to put it at the end of the installation, some of the installations will change the pyyaml version.

To Solve TypeError: load() missing 1 required positional argument: ‘Loader’ Error Here error is mentioning that your load() function is required param loader=Loader. So That you need to use safe_load() instead of load(). Second solution is Here pyyaml latest version 6.0 is not compatible with the current way Google Colab imports packages. So just downgrade pyyaml version to 5.4.1 which is compatible with the current way Google Colab imports and It will solve your error. use this command to downgrade pyyaml
and When im loading texthero package i got this error after i install pyyaml version 5.4.1 after i restart google colab i
rectify that Error

Ans:- !pip install pyyaml==5.4.1


The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .