2

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.

Laiborn
  • 21
  • 1
  • 3

3 Answers3

1

Maybe try

python3 -m pip install wandb ?

or

pip3 install wandb

morganmcg
  • 460
  • 2
  • 5
1

Restarting the runtime after doing the pip install did it for me.

0

Since you upgrade python, I think you can try

!python3.9 -m pip install wandb

I had the similar problem when the jupyter notebook kernel has multiple python options

xihajun
  • 37
  • 4