【问题标题】:How to install tensorflow 1.12 in Colab?如何在 Colab 中安装 tensorflow 1.12?
【发布时间】:2022-01-19 16:17:24
【问题描述】:

我一直在尝试在 Colab 中运行其他人的代码,并且已经为此苦苦挣扎了好几天(我试图避免安装它的 tensorflow 版本,但这似乎是必要的)。

我显然尝试过:

!pip install tensorflow==1.12

但它说:

错误:找不到满足要求 tensorflow==1.12 的版本(来自版本:1.13.1、1.13.2、1.14.0、1.15.0、1.15.2、1.15.3、1.15.4、 1.15.5、2.0.0、2.0.1、2.0.2、2.0.3、2.0.4、2.1.0、2.1.1、2.1.2、2.1.3、2.1.4、2.2.0rc0、2.2。 0rc1、2.2.0rc2、2.2.0rc3、2.2.0rc4、2.2.0、2.2.1、2.2.2、2.2.3、2.3.0rc0、2.3.0rc1、2.3.0rc2、2.3.0、2.3.1、 2.3.2、2.3.3、2.3.4、2.4.0rc0、2.4.0rc1、2.4.0rc2、2.4.0rc3、2.4.0rc4、2.4.0、2.4.1、2.4.2、2.4.3、2.4。 4、2.5.0rc0、2.5.0rc1、2.5.0rc2、2.5.0rc3、2.5.0、2.5.1、2.5.2、2.6.0rc0、2.6.0rc1、2.6.0rc2、2.6.0、2.6.1、 2.6.2、2.7.0rc0、2.7.0rc1、2.7.0、2.8.0rc0)

错误:未找到 tensorflow==1.12 的匹配分布

我也试过了:

!pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.12.0-cp36-cp36m-linux_x86_64.whl

得到:

错误:tensorflow-1.12.0-cp36-cp36m-linux_x86_64.whl 不是该平台支持的轮子。

有谁知道哪些命令会起作用? ????

【问题讨论】:

  • 你运行的是什么版本的python3? 1.2 应该适用于 python 3.4 到 3.6
  • 我以为我使用的是 3.6.3(与原始代码相同),但我检查了 !python --version 并且它是 3.7.12(好像我的 3.6.3 安装不是在职的)。你能帮我解决这个问题吗,伙计?
  • 不确定,我没有使用 colab 的经验。也许这个安装 python 3.5 的例子会有所帮助:colab.research.google.com/github/Dene33/mlcourse.ai/blob/master/…
  • 它有帮助。谢谢✌

标签: python-3.x tensorflow installation pip google-colaboratory


【解决方案1】:

感谢 William D. Irons 的帮助。这是我最终得到的代码:

from IPython.display import clear_output
import time
!add-apt-repository --yes ppa:deadsnakes/ppa
!apt-get update
!apt-get install python3.6
!apt-get install python3.6-dev

!wget https://bootstrap.pypa.io/get-pip.py && python3.6 get-pip.py
  
import sys

sys.path[2] = '/usr/lib/python36.zip'
sys.path[3] = '/usr/lib/python3.6'
sys.path[4] = '/usr/lib/python3.6/lib-dynload'
sys.path[5] = '/usr/local/lib/python3.6/dist-packages'
sys.path[7] = '/usr/local/lib/python3.6/dist-packages/IPython/extensions'

!pip install tensorflow==1.12

clear_output()
time.sleep(1)

import os
os.kill(os.getpid(), 9) #(This automatically restarts the runtime so the changes take effect)

重启后,你只需运行这个:

%tensorflow_version 1.x
import sys
sys.path[3] = '/usr/lib/python36.zip'
sys.path[4] = '/usr/lib/python3.6'
sys.path[5] = '/usr/lib/python3.6/lib-dynload'
sys.path[6] = '/usr/local/lib/python3.6/dist-packages'
sys.path[8] = '/usr/local/lib/python3.6/dist-packages/IPython/extensions'
!pip install tensorflow==1.12
from IPython.display import clear_output

import tensorflow as tf
clear_output()
print(tf.__version__) #(This is just to check that everything went right)

你准备好了。希望它可以帮助其他有同样问题的人?

【讨论】:

  • 我试过了,但它不再起作用了。 print(tf.__version__) 一直返回 1.15.2。你能检查一下解决方案吗?
  • 我刚刚检查过,你是对的。似乎 !pip install tensorflow==1.12 不起作用。很奇怪。如果你解决了,请分享你的解决方案,请
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-10
  • 1970-01-01
  • 1970-01-01
  • 2019-06-07
  • 2018-11-06
相关资源
最近更新 更多