Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Colab: "wandb" ModuleNotFoundError after installation

The "wandb" package cannot be found even after I see it has been listed in pip list.

To be more clear, I upgrade my python version to 3.9.15 in Colab, and then force to reinstall pip since somehow the pip module will disappear if I try to upgrade the python in colab. Below is my installation detail.

# update python version=3.9
!sudo apt-get update -y
!sudo apt-get install python3.9
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
!curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
!python3 get-pip.py --force-reinstall

#install python packages
!pip install wandb
!pip install pytorch-lightning

After this, everything works just fine. I can even see wandb 0.13.4 is installed if I run !pip list. Until I get the "wandb" ModuleNotFound error when I try to run the WandbLogger which imported from pytorch-lightning.

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-78-fdb2afd49644> in <module>
      9 name = name+"_"+args.student
     10 PATH = f"pretrain/{name}.pt"
---> 11 wandb_logger = WandbLogger(name=f"{name}",project="Shortcut Removal (COMP4471)")
     12 checkpoint_callback = ModelCheckpoint(dirpath="checkpoints", # where the ckpt will be saved
     13                                       filename=f"{name}_best", # the name of the best ckpt

/usr/local/lib/python3.7/dist-packages/pytorch_lightning/loggers/wandb.py in __init__(self, name, save_dir, offline, id, anonymous, version, project, log_model, experiment, prefix, agg_key_funcs, agg_default_func, **kwargs)
    271         if wandb is None:
    272             raise ModuleNotFoundError(
--> 273                 "You want to use `wandb` logger which is not installed yet,"
    274                 " install it with `pip install wandb`."  # pragma: no-cover
    275             )

ModuleNotFoundError: You want to use `wandb` logger which is not installed yet, install it with `pip install wandb`.

Im guessing maybe google colab always tries to access the directory under python3.7, yet I actually install my "wandb" package under python3.9? Maybe someone can tell me if my assumption is correct or not.

Thanks.

like image 347
Laiborn Avatar asked Oct 14 '25 21:10

Laiborn


1 Answers

Maybe try

python3 -m pip install wandb ?

or

pip3 install wandb

like image 178
morganmcg Avatar answered Oct 17 '25 09:10

morganmcg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!