如何在 Windows 上的 Python 2.7 上安装 Tensorflow?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45316569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 16:54:30  来源:igfitidea点击:

How to install Tensorflow on Python 2.7 on Windows?

pythontensorflowmodulepipinstall

提问by Jake Lam

I try to install TensorFlow via pip (pip install tensorflow) but get this error

我尝试通过 pip ( pip install tensorflow)安装 TensorFlow但收到此错误

could not find a version that satisfies the requirement tensorflow (from versions: )

找不到满足张量流要求的版本(来自版本:)

Is there a solution to this problem? I still wish to install it via pip

这个问题有解决方案吗?我仍然希望通过 pip 安装它

采纳答案by JCooke

Elaborating a bit on dirty_feri's answer as it's not quite up to date.

详细说明dirty_feri的答案,因为它不是最新的。

Tensorflow for Windows is only supported with Python 3.5 andPython 3.6 (since 1.2). As you are downloading via pip you will be receiving the latest 1.2 version so you should be able to run on 3.6.

Windows 版 Tensorflow 仅支持 Python 3.5Python 3.6(自 1.2 起)。当您通过 pip 下载时,您将收到最新的 1.2 版本,因此您应该能够在 3.6 上运行。

There should be no need to use the Anaconda version of Tensorflow, the distribution is not supported and, if you are running anaconda, the pip version does just fine.

应该不需要使用 Tensorflow 的 Anaconda 版本,不支持该发行版,如果您正在运行 anaconda,pip 版本就可以了。

If you still require python 2.7 support for other projects then may I suggest the use of an environment manager like anaconda or virtualenv to allow you to have multiple versions of python running nicely at once.

如果您仍然需要对其他项目的 python 2.7 支持,那么我可以建议使用像 anaconda 或 virtualenv 这样的环境管理器来允许您同时很好地运行多个版本的 python。

Once you have a supported version of python installed you should be able to run pip install tensorflowand it should install in a few minutes.

一旦安装了受支持的 python 版本,您应该能够运行pip install tensorflow,并且应该会在几分钟内安装。

Full installation instructions are available here: https://www.tensorflow.org/install/install_windows

完整安装说明可在此处获得:https: //www.tensorflow.org/install/install_windows

回答by XPloRR

If you only need TensorFlow because of Keras and your are on Python 2.7.x, you can avoid installing Tensorflow(Google) and replace it by CNTK(Microsoft). According to Jeong-Yoon LeeCNTK is a lot (about 2 to 4 times) faster than TensorFlow for LSTM (Bidirectional LSTM on IMDb Data and Text Generation via LSTM), while speeds for other type of neural networks are close to each other. Your Keras code does not need to be modified (I checked it with 2 examples of Keras using TensorFlow and succesfully replaced TensorFlow with CNTK, without changing anything the Keras code.

如果你因为 Keras 而只需要 TensorFlow 并且你在 Python 2.7.x 上,你可以避免安装 Tensorflow(Google) 并用 CNTK(Microsoft) 替换它。根据Jeong-Yoon Lee 的说法,对于 LSTM(IMDb 数据上的双向 LSTM 和通过 LSTM 生成文本),CNTK 比 TensorFlow 快很多(大约 2 到 4 倍),而其他类型的神经网络的速度彼此接近。你的 Keras 代码不需要修改(我用 2 个使用 TensorFlow 的 Keras 示例进行了检查,并成功地用 CNTK 替换了 TensorFlow,而没有更改任何 Keras 代码。

So how do you install it?

那么如何安装呢?

-CPU-only version of CNTK:

-仅 CPU 版本的 CNTK:

pip install https://cntk.ai/PythonWheel/CPU-Only/cntk-2.4-cp27-cp27m-win_amd64.whl

pip 安装 https://cntk.ai/PythonWheel/CPU-Only/cntk-2.4-cp27-cp27m-win_amd64.whl

-GPU version of CNTK:

-GPU版本的CNTK:

pip install https://cntk.ai/PythonWheel/GPU/cntk-2.4-cp27-cp27m-win_amd64.whl

pip 安装 https://cntk.ai/PythonWheel/GPU/cntk-2.4-cp27-cp27m-win_amd64.whl

-Test CNTK install:

- 测试 CNTK 安装:

python -c "import cntk; print(cntk.version)"

蟒蛇-c “进口cntk;打印(cntk)”

-Install Keras: The Python Deep Learning library

- 安装 Keras:Python 深度学习库

pip install keras

点安装keras

-Enable CNTK as Keras back end iso TensorFlow

- 启用 CNTK 作为 Keras 后端 iso TensorFlow

modify the "keras.json" file under %USERPROFILE%/.keras

修改 %USERPROFILE%/.keras 下的“keras.json”文件

{
    "epsilon": 1e-07, 
    "image_data_format": "channels_last", 
    "backend": "cntk", 
    "floatx": "float32" 
}

回答by J.Zhao

There is a great Github repo which has *.whl file to install. support py27 and py36

有一个很棒的 Github 存储库,其中包含要安装的 *.whl 文件。支持py27和py36

  1. go to fo40225's Github Repo tensorflow-windows-wheel
  2. find a tensorflow whl version and download
  3. pip install xxx.whl(xxx is your download whl file name)
  1. 转到fo40225 的 Github Repo tensorflow-windows-wheel
  2. 找到一个 tensorflow whl 版本并下载
  3. pip install xxx.whl(xxx 是你下载的 whl 文件名)

回答by BlooB

If you are using windows:

如果您使用的是窗户:

If you take a gander at TensorFlow website under windows PIP installation first line says.

如果您在 Windows PIP 安装第一行下的 TensorFlow 网站上查看一下。

"Pip installation on Windows

"在 Windows 上安装 Pip

TensorFlow supports only 64-bit Python 3.5 on Windows. We have tested the pip packages with the following distributions of Python:"

TensorFlow 在 Windows 上仅支持 64 位 Python 3.5。我们已经使用以下 Python 发行版测试了 pip 包:”

Now either install python 3.5, or use the unofficial version of Tensorflowfrom ANACONDA.

现在要么安装python 3.5,要么使用Tensorflowfrom的非官方版本ANACONDA

other way is to Download and install docker toolboxfor windows https://www.docker.com/docker-toolboxOpen a cmdwindow, and type: docker run -it b.gcr.io/tensorflow/tensorflowThis should bring up a linux shell. Type python and I think all would be well!

另一种方法是下载并安装docker toolboxwindowshttps://www.docker.com/docker-toolbox打开一个cmd窗口,然后输入:docker run -it b.gcr.io/tensorflow/tensorflow这应该会弹出一个linux shell. 输入 python,我想一切都会好起来的!

回答by Max Tkachenko

I found that Tensorflow can work on CPU under intergrated Ubuntu to Windows with any version of python.

我发现 Tensorflow 可以在集成 Ubuntu 到 Windows 的任何版本的 python 下在 CPU 上工作。

  1. You may install Ubuntu directly from Windows Store (https://www.microsoft.com/ru-ru/p/ubuntu/9nblggh4msv6)
  2. pip: curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py
  3. sudo pip install tensorflow
  1. 您可以直接从 Windows Store ( https://www.microsoft.com/ru-ru/p/ubuntu/9nblggh4msv6)安装 Ubuntu
  2. 点: curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py
  3. sudo pip install tensorflow