我在 Kaggle 服务器上运行 .ipynb notebook。
在第一个代码单元格中,导入模块时,具体来自google.patches的cv2_imshow如下,
from google.colab.patches import cv2_imshow
我得到这个错误:
/opt/conda/lib/python3.7/site-packages/IPython/utils/traitlets.py:5: UserWarning: IPython.utils.traitlets has moved to a top-level traitlets package.
warn("IPython.utils.traitlets has moved to a top-level traitlets package.")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_27/1840971195.py in <module>
18
19 # Display images using OpenCV
---> 20 from google.colab.patches import cv2_imshow # Importing cv2_imshow from google.patches to display images
21
22 # Ignore warnings
/opt/conda/lib/python3.7/site-packages/google/colab/__init__.py in <module>
24 from google.colab import _tensorflow_magics
25 from google.colab import auth
---> 26 from google.colab import data_table
27 from google.colab import drive
28 from google.colab import files
/opt/conda/lib/python3.7/site-packages/google/colab/data_table.py in <module>
164
165
--> 166 class _JavascriptModuleFormatter(_IPython.core.formatters.BaseFormatter):
167 format_type = _traitlets.Unicode(_JAVASCRIPT_MODULE_MIME_TYPE)
168 print_method = _traitlets.ObjectName('_repr_javascript_module_')
/opt/conda/lib/python3.7/site-packages/google/colab/data_table.py in _JavascriptModuleFormatter()
165
166 class _JavascriptModuleFormatter(_IPython.core.formatters.BaseFormatter):
--> 167 format_type = _traitlets.Unicode(_JAVASCRIPT_MODULE_MIME_TYPE)
168 print_method = _traitlets.ObjectName('_repr_javascript_module_')
169
AttributeError: module 'IPython.utils.traitlets' has no attribute 'Unicode'
跑步后
from traitlets import *
print(traitlets)
<module 'traitlets.traitlets' from '/opt/conda/lib/python3.7/site-packages/traitlets/traitlets.py'>
并重新运行问题行,以处理错误消息的顶部,
/opt/conda/lib/python3.7/site-packages/IPython/utils/traitlets.py:5: UserWarning: IPython.utils.traitlets has moved to a top-level traitlets package.
warn("IPython.utils.traitlets has moved to a top-level traitlets package.")
错误消息的这一部分消失了,但其他所有内容都保持不变。
google-colab 1.0.0
留下这个问题以防万一有人遇到类似问题并分享这个堆栈溢出答案链接来自一个对我有帮助的相关问题:google-colab library does not exist in the Kaggle Kernel.
以及解决连接到谷歌驱动器的有用链接: