python 谷歌协作实验室:安装后出现“wandb”ModuleNotFoundError

nnvyjq4y  于 2023-03-28  发布在  Python
关注(0)|答案(3)|浏览(337)

“wandb”包即使在我看到它已经在pip list中列出后也找不到。
为了更清楚,我在Colab中将我的python版本升级到3.9.15,然后强制重新安装pip,因为如果我尝试在colab中升级python,不知何故pip模块会消失。下面是我的安装细节。

# 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

在此之后,一切正常。如果我运行!pip list,我甚至可以看到wandb 0.13.4已经安装。直到我尝试运行从pytorch-lightning导入的WandbLogger时出现“wandb”ModuleNotFound错误。

---------------------------------------------------------------------------
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`.

我猜也许google colab总是试图访问python3.7下的目录,但我实际上是在python3.9下安装我的“wandb”包?也许有人能告诉我我的假设是否正确。
谢谢。

31moq8wy

31moq8wy1#

也许试试
一个月一个月

pip3 install wandb

zbwhf8kr

zbwhf8kr2#

在完成pip安装后重新启动运行时对我来说就是这样。

y3bcpkx1

y3bcpkx13#

既然你升级了python,我想你可以试试

!python3.9 -m pip install wandb

当jupyter notebook内核有多个python选项时,我也遇到了类似的问题

相关问题