How can I fix an error like `AttributeError: module 'wandb' has no attribute ...`?

If you encounter an error like AttributeError: module 'wandb' has no attribute 'init' or AttributeError: module 'wandb' has no attribute 'login' when importing wandb in Python, wandb is not installed or the installation is corrupted, but a wandb directory exists in the current working directory. To fix this error, uninstall wandb, delete the directory, then install wandb:

pip uninstall wandb; rm -rI wandb; pip install wandb

Last modified February 20, 2025: c1984ba