colab 中 安装 tensorflow example 报错以及解决方案

本文最后更新于:2023年8月12日 中午

运行

1
!pip install git+https://github.com/tensorflow/examples.git

报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Collecting git+https://github.com/tensorflow/examples.git
Cloning https://github.com/tensorflow/examples.git to /tmp/pip-req-build-u7_jdkn8
Running command git clone --filter=blob:none --quiet https://github.com/tensorflow/examples.git /tmp/pip-req-build-u7_jdkn8
Resolved https://github.com/tensorflow/examples.git to commit e3849ccb6d981aad311f0174281c8575d5e21646
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
Preparing metadata (setup.py) ... error
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

ai-colab-tensorflow-example-01

解决方案

1
2
3
# 参考 https://github.com/tensorflow/tensorflow/issues/60106#issuecomment-1487638835
!apt remove git -y # remove any degraded git module
!apt-get install git -y && git clone https://github.com/tensorflow/examples.git # Install git first, then clone.
1
2
3
4
# 参考 https://github.com/tensorflow/tensorflow/issues/60106#issuecomment-1511149579
import sys
sys.path.append('/content/examples')
import tensorflow_examples

扩展

  1. tensorflow/examples: TensorFlow examples: https://github.com/tensorflow/examples

同步

  1. StackOverflow: How to install tensorflow examples in colab
    1. Q: https://stackoverflow.com/q/76083008/15599248
    2. A: https://stackoverflow.com/a/76083019/15599248

colab 中 安装 tensorflow example 报错以及解决方案
https://cc01cc.com/2023/04/23/ai-colab-tensorflow-example/index.html
作者
cc01cc(zeo)
发布于
2023年4月23日
更新于
2023年8月12日
许可协议