Python 在 Windows 中使用 anaconda 安装 tensorflow

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37130489/
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 18:55:01  来源:igfitidea点击:

Installing tensorflow with anaconda in windows

pythonwindowsanacondatensorflowconda

提问by Ahmad

I have installed Anaconda on Windows 64 bit. I have downloaded PyCharm for creating a project and in the terminal of PyCharm I have installed numpy, scipy, matplotlibusing the following commands:

我已经在 Windows 64 位上安装了 Anaconda。我已经下载了用于创建项目的 PyCharm,并在 PyCharm 的终端中安装了numpy, scipymatplotlib使用以下命令:

conda install numpy
conda install scipy
conda install matplotlib

I am not able to install Tensorflow in the same way I installed these other packages. How should I install it?

我无法像安装这些其他软件包一样安装 Tensorflow。我应该如何安装它?

回答by Muhammad Hannan

Google has recently launched a newer version of Tesnsorflow r0.12 which include support of Windows both CPU and GPU version can now be installed using Python >=3.5.2 (only 64-bit) version.

谷歌最近推出了更新版本的 Tesnsorflow r0.12,其中包括对 Windows 的支持,现在可以使用 Python >=3.5.2(仅 64 位)版本安装 CPU 和 GPU 版本。

For CPU only version open command promptand enter follow command

对于仅限 CPU 的版本,打开命令提示符并输入以下命令

pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0rc0-cp35-cp35m-win_amd64.whl

Follow this Tensorflow on Windowsfor step by step instructions.

按照Windows 上的 Tensorflow获取分步说明。

UPDATE

更新

To install current latest version please run following command:

要安装当前最新版本,请运行以下命令:

pip install tensorflow #CPU only
pip install tensorflow-gpu #For GPU support

回答by SilverSurfer

To install TF on windows, follow the below-mentioned steps:

要在 Windows 上安装 TF,请按照以下步骤操作:

conda create --name tensorflow python=3.5
activate tensorflow
conda install jupyter
conda install scipy
pip install tensorflow-gpu

Use pip install tensorflowin place of pip install tensorflow-gpu, in case if you want to install CPU only version of TF.

如果您想安装仅限 CPU 的 TF 版本,请使用pip install tensorflow代替pip install tensorflow-gpu

Note: This installation has been tested with Anaconda Python 3.5 (64 bit). I have also tried the same installation steps with (a) Anaconda Python 3.6 (32 bit), (b) Anaconda Python 3.6 (64 bit), and (c) Anaconda Python 3.5 (32 bit), but all of them (i.e. (a), (b) and (c) ) failed.

注意:此安装已使用Anaconda Python 3.5(64 位)进行测试。我还尝试了与 (a) Anaconda Python 3.6(32 位)、(b)Anaconda Python 3.6(64 位)和(c)Anaconda Python 3.5(32 位)相同的安装步骤,但所有这些(即( a)、(b) 和 (c) ) 失败。

回答by learningstack

Google has announced support for tensorflow on Windows. Please follow instructions at https://developers.googleblog.com/2016/11/tensorflow-0-12-adds-support-for-windows.html. Please note CUDA8.0 is needed for GPU installation.

Google 已宣布在 Windows 上支持 tensorflow。请按照https://developers.googleblog.com/2016/11/tensorflow-0-12-adds-support-for-windows.html 上的说明进行操作。请注意 GPU 安装需要 CUDA8.0。

If you have installed the 64-bit version of Python 3.5 (either from Python.org or Anaconda), you can install TensorFlow with a single command: C:> pip install tensorflow

如果您已经安装了 64 位版本的 Python 3.5(来自 Python.org 或 Anaconda),您可以使用单个命令安装 TensorFlow:C:> pip install tensorflow

For GPU support, if you have CUDA 8.0 installed, you can install the following package instead: C:> pip install tensorflow-gpu

对于 GPU 支持,如果您安装了 CUDA 8.0,则可以安装以下软件包:C:> pip install tensorflow-gpu

回答by Nabeel Ahmed

Currently tensorflow has binaries only for Unix based OS i.e. Ubuntu Mac OS X - that's why no mention of Windows in setup docs.

目前 tensorflow 的二进制文件仅适用于基于 Unix 的操作系统,即 Ubuntu Mac OS X - 这就是为什么在安装文档中没有提到 Windows 的原因。

There are long discussions on Github:

Github上有很长的讨论:



A SOanswer - tensorflow — is it or will it (sometime soon) be compatible with a windows workflow?

一个SO答案 - tensorflow - 它是还是会(很快)与 Windows 工作流程兼容?



Suggestion:

建议:

For now, on Windows, the easiest way to get started with TensorFlow would be to use Docker: http://tensorflow.org/get_started/os_setup.md#docker-based_installation

It should become easier to add Windows support when Bazel (the build system we are using) adds support for building on Windows, which is on the roadmap for Bazel 0.3. You can see the full Bazel roadmap here.

目前,在 Windows 上,开始使用 TensorFlow 的最简单方法是使用 Dockerhttp: //tensorflow.org/get_started/os_setup.md#docker-based_installation

当 Bazel(我们正在使用的构建系统)添加对在 Windows 上构建的支持时,添加 Windows 支持应该会变得更容易,这在 Bazel 0.3 的路线图上。您可以在此处查看完整的 Bazel 路线图。

Or simply use a Linux VM(using VMPlayer), and the stated steps will setup it up for you.

或者简单地使用 Linux VM(使用 VMPlayer),所述步骤将为您设置。



For PyCharm- Once condaenvironment will be created, you'll need to set the new interpretor (in conda environment) as the interpretorto use in PyCharm:

对于 PyCharm-conda创建环境后,您需要将新解释器(在 conda 环境中)设置为interpretor要使用的PyCharm

Now to use the conda interpreter from PyCharm go to file> settings> project> interpreter, select Add localin the project interpreter field (the little gear wheel) and browse the interpreter or past the path.

现在要使用 PyCharm 中的 conda 解释器,请转到文件>设置>项目>解释器,在项目解释器字段(小齿轮)中选择添加本地并浏览解释器或经过路径。

The default location - the environment lives under conda_root/envs/tensorflow. The new python interpreter 'll be at conda_root/envs/tensorflow/bin/pythonX.X, such that the site-packageswill be in conda_root/envs/tensorflow/lib/pythonX.X/site-packages.

默认位置 - 环境位于conda_root/envs/tensorflow. 新的 python 解释器将在conda_root/envs/tensorflow/bin/pythonX.X,这样site-packages将在conda_root/envs/tensorflow/lib/pythonX.X/site-packages.

回答by MartinD

I was able to install tensorflow on windows following the instructions on tensorflow.org, using the conda method of installation, as given here: https://www.tensorflow.org/get_started/os_setup#anaconda_installation. There are small differences on how to activate an 'environment' on windows, you call 'activate' directly without the 'source'. So, for me after installing anaconda the steps where:

我能够按照 tensorflow.org 上的说明,使用 conda 安装方法在 Windows 上安装 tensorflow,如下所示:https://www.tensorflow.org/get_started/os_setup#anaconda_installation 。如何在 Windows 上激活“环境”存在细微差别,您可以在没有“源”的情况下直接调用“激活”。因此,对我而言,安装 anaconda 后的步骤如下:

C:\Users\Dunschm>conda create -n tensorflow python=3.5
C:\Users\Dunschm>activate tensorflow
(tensorflow) C:\Users\Dunschm>conda install -c conda-forge tensorflow

回答by Narahari B M

activate tensorflow

activate tensorflow

conda install -c conda-forge tensorflowworked for me.

conda install -c conda-forge tensorflow为我工作。

None of the other steps mentioned online helped, I found it herewhen trying to install an older version.

在线提到的其他步骤都没有帮助,我在尝试安装旧版本时在这里找到了它。

Eventhough the steps mentioned in the link seems to be for MAC OS X/Linux it worked in windows 7

尽管链接中提到的步骤似乎适用于 MAC OS X/Linux,但它在 Windows 7 中有效

You can install spyder along with this conda install spyder

您可以同时安装 spyder conda install spyder

回答by Doru C

This worked for me:

这对我有用:

conda create -n tensorflow python=3.5
activate tensorflow
conda install -c conda-forge tensorflow

Open Anaconda Navigator.

打开 Anaconda 导航器。

Change the dropdown of "Applications on" from "root" to "tensorflow"

将“Applications on”的下拉菜单从“ root”改为“ tensorflow

see screenshot

看截图

Launch Spyder

启动 Spyder

Run a little code to validate you're good to go:

运行一些代码来验证您是否可以使用:

import tensorflow as tf
node1 = tf.constant(3, tf.float32)
node2 = tf.constant(4) # also tf.float32 implicitly
print(node1, node2)

or

或者

hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

回答by Harshit Satya

I have python 3.5 with anaconda. First I tried everything given above but it did not work for me on windows 10 64bit. So I simply tried:-

我有带有 anaconda 的 python 3.5。首先,我尝试了上面给出的所有内容,但在 Windows 10 64 位上对我不起作用。所以我只是尝试:-

  1. Open the command prompt
  2. Check for python version for which you want to install tensorflow, if you have multiple versions of python.
  3. If you just have one version, then type in cmd:

    C:/>conda install tensorflow 
    

    for multiple versions of python, type in cmd:

    C:/>conda install tensorflow python=version(e.g.python=3.5)
    
  1. 打开命令提示符
  2. 如果您有多个版本的 python,请检查要为其安装 tensorflow 的 python 版本。
  3. 如果你只有一个版本,那么输入cmd:

    C:/>conda install tensorflow 
    

    对于多个版本的python,输入cmd:

    C:/>conda install tensorflow python=version(e.g.python=3.5)
    

It works, just give it a try.
After installation open ipython console and import tensorflow:

它有效,试一试。
安装后打开 ipython 控制台并导入 tensorflow:

import tensorflow

If tensorflow installed properly then you are ready to go. Enjoy machine learning:-)

如果 tensorflow 安装正确,那么你就可以开始了。享受机器学习:-)

回答by Shahram Tavakoli

I found a more recent blog postin Anaconda which instructs how to install the TF easily. I used:

我在 Anaconda 中找到了一篇更新的博客文章,其中介绍了如何轻松安装 TF。我用了:

conda create -n tensorflow_env tensorflow

Or for the GPU version (Make sure that you have NVIDIA GPU)

或者对于 GPU 版本(确保您有 NVIDIA GPU)

conda create -n tensorflow_gpuenv tensorflow-gpu

This way you will have different environments for different TFs.

通过这种方式,您将为不同的 TF 拥有不同的环境。

回答by Legend_Ari

The following command from inside your command window (and preferably, conda environment) will work provided you have an Nvidia graphics card.

如果您有 Nvidia 显卡,则命令窗口(最好是 conda 环境)中的以下命令将起作用。

conda install tensorflow-gpu