简体   繁体   English

在 Windows 中使用 anaconda 安装 tensorflow

[英]Installing tensorflow with anaconda in windows

I have installed Anaconda on Windows 64 bit.我已经在 Windows 64 位上安装了 Anaconda。 I have downloaded PyCharm for creating a project and in the terminal of PyCharm I have installed numpy , scipy , matplotlib using the following commands:我已经下载了用于创建项目的 PyCharm,并在 PyCharm 的终端中使用以下命令安装了numpyscipymatplotlib

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.我无法像安装这些其他软件包一样安装 Tensorflow。 How should I install it?我应该如何安装它?

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

For CPU only version open command prompt and 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 Windows for 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

UPDATE 2020 2020 年更新

Tensorflow 2.0 now has a single package for both CPU and GPU version, simply run Tensorflow 2.0 现在有一个 CPU 和 GPU 版本的包,只需运行

pip install tensorflow

If your're using Anaconda you can install Tensorflow GPU version and all of its dependencies (CUDA, cuDNN) by running:如果您使用的是 Anaconda,则可以通过运行以下命令安装 Tensorflow GPU 版本及其所有依赖项(CUDA、cuDNN):

conda install -c tensorflow-gpu

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 tensorflow in place of pip install tensorflow-gpu , in case if you want to install CPU only version of TF.使用pip install tensorflow代替pip install tensorflow-gpu ,以防您想安装仅限 CPU 的 TF 版本。

Note: This installation has been tested with Anaconda Python 3.5 (64 bit) .注意:此安装已使用Anaconda Python 3.5(64 位)进行测试。 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 (ie (a), (b) and (c) ) failed.我还尝试了与 (a) Anaconda Python 3.6(32 位)、(b)Anaconda Python 3.6(64 位)和(c)Anaconda Python 3.5(32 位)相同的安装步骤,但所有这些(即( a)、(b) 和 (c) ) 失败。

Currently tensorflow has binaries only for Unix based OS ie 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 SO answer - 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目前,在 Windows 上,开始使用 TensorFlow 的最简单方法是使用 Dockerhttp : //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.当 Bazel(我们正在使用的构建系统)添加对在 Windows 上构建的支持时,添加 Windows 支持应该会变得更容易,这在 Bazel 0.3 的路线图上。 You can see the full Bazel roadmap here.您可以在此处查看完整的 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 conda environment will be created, you'll need to set the new interpretor (in conda environment) as the interpretor to use in PyCharm :对于 PyCharm - 创建conda环境后,您需要将新解释器(在 conda 环境中)设置为在PyCharm使用的interpretor

Now to use the conda interpreter from PyCharm go to file > settings > project > interpreter , select Add local in 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 .默认位置 - 环境位于conda_root/envs/tensorflow The new python interpreter 'll be at conda_root/envs/tensorflow/bin/pythonX.X , such that the site-packages will be in conda_root/envs/tensorflow/lib/pythonX.X/site-packages .新的 python 解释器将位于conda_root/envs/tensorflow/bin/pythonX.X ,这样site-packages将位于conda_root/envs/tensorflow/lib/pythonX.X/site-packages

Google has announced support for tensorflow on Windows. Google 已宣布在 Windows 上支持 tensorflow。 Please follow instructions at https://developers.googleblog.com/2016/11/tensorflow-0-12-adds-support-for-windows.html .请按照https://developers.googleblog.com/2016/11/tensorflow-0-12-adds-support-for-windows.html 上的说明进行操作。 Please note CUDA8.0 is needed for GPU installation.请注意 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

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 .我能够按照 tensorflow.org 上的说明,使用 conda 安装方法在 Windows 上安装 tensorflow,如下所示: 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'.如何在 Windows 上激活“环境”存在细微差别,您可以在没有“源”的情况下直接调用“激活”。 So, for me after installing anaconda the steps where:因此,对我而言,安装 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

activate tensorflow

conda install -c conda-forge tensorflow worked for me. conda install -c conda-forge tensorflow对我conda install -c conda-forge tensorflow

None of the other steps mentioned online helped, I found it here when 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

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))

I have python 3.5 with anaconda.我有带有 anaconda 的 python 3.5。 First I tried everything given above but it did not work for me on windows 10 64bit.首先,我尝试了上面给出的所有内容,但在 Windows 10 64 位上对我不起作用。 So I simply tried:-所以我只是尝试:-

  1. Open the command prompt打开命令提示符
  2. Check for python version for which you want to install tensorflow, if you have multiple versions of python.如果您有多个版本的 python,请检查要为其安装 tensorflow 的 python 版本。
  3. If you just have one version, then type in cmd:如果你只有一个版本,那么输入cmd:

     C:/>conda install tensorflow

    for multiple versions of python, type in cmd:对于多个版本的python,输入cmd:

     C:/>conda install tensorflow python=version(egpython=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.如果 tensorflow 安装正确,那么你就可以开始了。 Enjoy machine learning:-)享受机器学习:-)

I found a more recent blog post in Anaconda which instructs how to install the TF easily.我在 Anaconda 中找到了一篇更新的博客文章,其中介绍了如何轻松安装 TF。 I used:我用过:

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 拥有不同的环境。

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

conda install tensorflow-gpu 

1) Update conda 1)更新康达

Run the anaconda prompt as administrator以管理员身份运行 anaconda prompt

conda update -n base -c defaults conda

2) Create an environment for python new version say, 3.6 2)为python新版本创建一个环境说,3.6

conda create --name py36 python=3.6

3) Activate the new environment 3)激活新环境

conda activate py36

4) Upgrade pip 4) 升级pip

pip install --upgrade pip

5) Install tensorflow 5)安装张量流

pip install https://testpypi.python.org/packages/db/d2/876b5eedda1f81d5b5734277a155fa0894d394a7f55efa9946a818ad1190/tensorflow-0.12.1-cp36-cp36m-win_amd64.whl

If it doesn't work如果它不起作用

If you have problem with wheel at the environment location, or pywrap_tensorflow problem,如果你在环境位置有轮子问题,或者 pywrap_tensorflow 问题,

 pip install tensorflow --upgrade --force-reinstall

The above steps以上步骤

conda install -c conda-forge tensorflow

will work for Windows 10 as well but the Python version should be 3.5 or above.也适用于 Windows 10,但 Python 版本应为 3.5 或更高版本。 I have used it with Anaconda Python version 3.6 as the protocol buffer format it refers to available on 3.5 or above.我已经将它与 Anaconda Python 3.6 版一起用作它所指的协议缓冲区格式,可用于 3.5 或更高版本。 Thanks, Sandip谢谢,桑迪普

This is what I did for Installing Anaconda Python 3.6 version and Tensorflow on Window 10 64bit.And It was success!这就是我在 Window 10 64bit 上安装 Anaconda Python 3.6 版本和 Tensorflow 所做的事情。它成功了!

  1. Go to https://www.continuum.io/downloads to download Anaconda Python 3.6 version for Window 64bit.前往https://www.continuum.io/downloads下载适用于 Window 64 位的 Anaconda Python 3.6 版本。

  2. Create a conda environment named tensorflow by invoking the following command:通过调用以下命令创建一个名为 tensorflow 的 conda 环境:

    C:> conda create -n tensorflow C:> conda create -n tensorflow

  3. Activate the conda environment by issuing the following command:通过发出以下命令激活 conda 环境:

    C:> activate tensorflow (tensorflow)C:> # Your prompt should change C:> activate tensorflow (tensorflow)C:> # 你的提示应该改变

  4. Go to http://www.lfd.uci.edu/~gohlke/pythonlibs/enter code here download “tensorflow-1.0.1-cp36-cp36m-win_amd64.whl”.http://www.lfd.uci.edu/~gohlke/pythonlibs/在这里输入代码下载“tensorflow-1.0.1-cp36-cp36m-win_amd64.whl”。 (For my case, the file will be located in “C:\\Users\\Joshua\\Downloads” once after downloaded) (就我而言,文件下载后将位于“C:\\Users\\Joshua\\Downloads”中)

  5. Install the Tensorflow by using the following command:使用以下命令安装 Tensorflow:

    (tensorflow)C:>pip install C:\\Users\\Joshua\\Downloads\\ tensorflow-1.0.1-cp36-cp36m-win_amd64.whl (tensorflow)C:>pip install C:\\Users\\Joshua\\Downloads\\tensorflow-1.0.1-cp36-cp36m-win_amd64.whl

This is what I got after the installing:这是我安装后得到的: 在此处输入图片说明

  1. Validate installation by entering following command in your Python environment:通过在 Python 环境中输入以下命令来验证安装:

    import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print(sess.run(hello))将张量流导入为 tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print(sess.run(hello))

If the output you got is 'Hello, TensorFlow!',that means you have successfully install your Tensorflow.如果你得到的输出是“你好,TensorFlow!”,这意味着你已经成功安装了你的 Tensorflow。

  • Install Anaconda for Python 3.5 - Can install from here for 64 bit windows为 Python 3.5 安装 Anaconda - 可以从这里为 64 位 Windows 安装

  • Then install TensorFlow from here然后从这里安装 TensorFlow

(I tried previously with Anaconda for Python 3.6 but failed even after creating Conda env for Python3.5) (我之前尝试过使用 Anaconda for Python 3.6 但即使在为 Python3.5 创建 Conda env 之后也失败了)

Additionally if you want to run a Jupyter Notebook and use TensorFlow in it.此外,如果您想运行 Jupyter Notebook 并在其中使用 TensorFlow。 Use following steps.使用以下步骤。

Change to TensorFlow env:更改为 TensorFlow 环境:

C: > activate tensorflow
(tensorflow) C: > pip install jupyter notebook

Once installed, you can launch Jupyter Notebook and test安装后,您可以启动 Jupyter Notebook 并进行测试

(tensorflow) C: > jupyter notebook

Open anaconda prompt打开 anaconda 提示

make sure your pip version is updated确保您的 pip 版本已更新

and you have python 3.4 3.5 or 3.6你有 python 3.4 3.5 或 3.6

Just run the command只需运行命令

pip install --upgrade tensorflow

you can take help from the documentation and video您可以从文档视频中获取帮助

Goodluck好运

I use windows 10, Anaconda and python 2. A combination of mentioned solutions worked for me:我使用 Windows 10、Anaconda 和 python 2。上述解决方案的组合对我有用:

Once you installed tensorflow using:使用以下命令安装 tensorflow 后:

C:\\Users\\Laleh>conda create -n tensorflow python=3.5 # use your python version C:\\Users\\Laleh>conda create -n tensorflow python=3.5 # 使用你的python 版本

C:\\Users\\Laleh>activate tensorflow C:\\Users\\Laleh>激活张量流

(tensorflow) C:\\Users\\Laleh>conda install -c conda-forge tensorflow (tensorflow) C:\\Users\\Laleh>conda install -c conda-forge tensorflow

Then I realized tensorflow can not be imported in jupyter notebook, although it can work in commad windows.然后我意识到 tensorflow 不能在 jupyter notebook 中导入,尽管它可以在命令窗口中工作。 To solve this issue first I checked:为了首先解决这个问题,我检查了:

jupyter kernelspec list jupyter 内核规格列表

I removeed the Jupyter kernelspec, useing:我删除了 Jupyter kernelspec,使用:

jupyter kernelspec remove python2 jupyter kernelspec 删除 python2

Now, the jupyter kernelspec list is pointing to the correct kernel.现在,jupyter kernelspec 列表指向正确的内核。 Again, I activate tensorflow and installed notebook in its environment:再次,我激活 tensorflow 并在其环境中安装 notebook:

C:\\Users\\Laleh>activate tensorflow C:\\Users\\Laleh>激活张量流

(tensorflow)C:> conda install notebook (tensorflow)C:> conda 安装笔记本

Also if you want to use other libraries such as matplotlib, they should be installed separately in tensorflow environment另外如果要使用matplotlib等其他库,需要在tensorflow环境中单独安装

(tensorflow)C:> conda install -c conda-forge matplotlib (tensorflow)C:> conda install -c conda-forge matplotlib

Now everything works fine for me.现在一切对我来说都很好。

This documentation link is helpful and worked for me.这个文档链接对我很有帮助。 Installs all dependencies and produces a working Anaconda.安装所有依赖项并生成一个可用的 Anaconda。 Or this answer is also helpful if you want to use it with spyder或者,如果您想将其与 spyder 一起使用,答案也很有帮助

If you have anaconda version 2.7 installed on your windows, then go to anaconda prompt, type these two commands:如果您的 Windows 上安装了 anaconda 2.7 版,请转到 anaconda 提示符,键入以下两个命令:

  1. Create a conda environment for tensorflow using conda create -n tensorflow_env tensorflow使用conda create -n tensorflow_env tensorflow为 tensorflow conda create -n tensorflow_env tensorflow
  2. activate the tensorflow using conda activate tensorflow_env使用conda activate tensorflow_env

If it is activated, then the base will be replaced by tensorflow_env ie now it will show (tensorflow_env) C:\\Users>如果它被激活,那么基础将被tensorflow_env替换,即现在它将显示(tensorflow_env) C:\\Users>

You can now use import tensorflow as tf for using tensorflow in your code.您现在可以使用import tensorflow as tf在您的代码中使用 tensorflow。

I tried many things but always faced some issue or other.我尝试了很多东西,但总是遇到一些问题或其他问题。 Below steps with specific version only worked for me.以下特定版本的步骤仅对我有用。

1> Create virtual env 1> 创建虚拟环境

#conda create -n tensorflow pip python=3.5

2> activate env #activate tensorflow #conda info --envs 2> 激活环境 #activate tensorflow #conda info --envs

3> Install tensorflow 3> 安装tensorflow

#conda install -c conda-forge tensorflow

this will install tensorflow 1.10.0这将安装 tensorflow 1.10.0

#python -m pip install --upgrade pip
#pip install setuptools==39.1.0

3> Install keras 3>安装keras

#pip install keras==2.2.2

Testing测试

(tensorflow) C:\WINDOWS\system32>python
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 16:05:27) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> import keras
Using TensorFlow backend.
>>>

"Conda" installs some of the special packages that might have compiled in C or other languages. “Conda”安装一些可能用 C 或其他语言编译的特殊包。 You can use "pip install tensorflow" and it will work.您可以使用“pip install tensorflow”,它会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM