Python 使用 anaconda 在 Windows 上安装 tensorflow

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

Install tensorflow on Windows with anaconda

pythonanacondatensorflow

提问by Valentina

I am trying to install Tensorflow on my Windows PC. Since I have already install and used Anaconda on Python (3.5), I have followed the instructions https://www.tensorflow.org/versions/r0.8/get_started/os_setup.html#anaconda-environment-installation.

我正在尝试在我的 Windows PC 上安装 Tensorflow。由于我已经在 Python (3.5) 上安装并使用了 Anaconda,因此我已按照https://www.tensorflow.org/versions/r0.8/get_started/os_setup.html#anaconda-environment-installation的说明进行操作。

After the creation of the conda environment called tensorflow, I have tested my installation with:

在创建名为 tensorflow 的 conda 环境之后,我测试了我的安装:

$ python
Import tensorflow as tf

But I got the error :

但我得到了错误:

ImportError: no module named 'tensorflow'

Does anyone know what I missed?

有谁知道我错过了什么?

Thank you very much!

非常感谢!

采纳答案by mrry

UPDATE:Since TensorFlow 0.12, we have published packages for Windows. You can install the CPU-only version with the following command:

更新:从 TensorFlow 0.12 开始,我们已经发布了适用于 Windows 的软件包。您可以使用以下命令安装仅 CPU 版本:

C:\> pip install tensorflow

…and the GPU-accelerated version with:

...以及带有以下功能的 GPU 加速版本:

C:\> pip install tensorflow-gpu

Note that you will need the 64-bitversion of Python 3.5 installed for the above commands to work.

请注意,您需要安装64 位版本的 Python 3.5 才能运行上述命令。



TensorFlow is not currently supported on Windows, and none of the official binary packages work on Windows. We are currently working on adding support for Windows, but this effort is in the early stages.

TensorFlow目前在 Windows 上不受支持,并且没有任何官方二进制包在 Windows 上工作。我们目前正在努力增加对 Windows 的支持,但这项工作还处于早期阶段。

See the answers to this questionfor suggestions on how to run TensorFlow using Docker or Bash for Windows.

有关如何使用 Docker 或 Bash for Windows 运行 TensorFlow 的建议,请参阅此问题的答案。

回答by Omar Shehata

It looks like you need to activate the virtual environment that TensorFlow was installed in. When you activate the virtual environment, it will appear in parenthesis in your command prompt, like in the example tutorial:

看起来您需要激活安装 TensorFlow 的虚拟环境。当您激活虚拟环境时,它会出现在命令提示符中的括号中,如示例教程中所示:

$ source activate tensorflow
(tensorflow)$  # Your prompt should change

The source command only works on Linux/Mac as far as I'm aware, so for windows you'll have to follow the instructions here:

据我所知,source 命令仅适用于 Linux/Mac,因此对于 Windows,您必须按照此处的说明进行操作:

http://conda.pydata.org/docs/using/envs.html#change-environments-activate-deactivate

http://conda.pydata.org/docs/using/envs.html#change-environments-activate-deactivate

In general, the script file that handles the activation is location in [your_environment]/bin/activateif you're curious about what it does.

通常,[your_environment]/bin/activate如果您对它的作用感到好奇,那么处理激活的脚本文件就在 location 中。

So basically the tensorflow files are installed inside this environment folder, and Python won't be able to find them unless this folder is added to the PATH where it searches for libraries, and this is essentially what activating the environment does!

所以基本上tensorflow文件安装在这个环境文件夹中,除非将此文件夹添加到搜索库的PATH中,否则Python将无法找到它们,这本质上就是激活环境的作用!

回答by Sandip Guha

The above provided steps will install the TensorFlow in your Windows System but still you might face problem in making it available in your Jupyter notebook - hence integrating steps from different places together to have a complete solution:

上面提供的步骤将在您的 Windows 系统中安装 TensorFlow,但您仍然可能会在 Jupyter notebook 中使用它时遇到问题 - 因此将来自不同地方的步骤集成在一起以获得完整的解决方案:

How to install Tensorflow in Anaconda environment on windows 10 1) Download and install Anaconda 3.6 (3.5 and above) in your system from Anaconda site. 2) Restart your system 3) Create virtual environment by following command: conda create -n tensorflow

如何在 Windows 10 上的 Anaconda 环境中安装 Tensorflow 1) 从 Anaconda 站点下载并在您的系统中安装 Anaconda 3.6(3.5 及更高版本)。2)重新启动系统 3)通过以下命令创建虚拟环境:conda create -n tensorflow

4) Activate the virtual environment

4)激活虚拟环境

C:> activate tensorflow

C:> 激活张量流

(tensorflow)C:> # Your prompt should change TensorFlow in anaconda5) Following steps should start installing Tensorflow in virtual environment

(tensorflow)C:> # 你的提示应该在 anaconda 中更改 TensorFlow5) 以下步骤应该开始在虚拟环境中安装 Tensorflow

(tensorflow)C:> conda install -c conda-forge tensorflow 6) Now you may enter in python and work on tensorflow (tensorflow)C:> python

(tensorflow)C:> conda install -c conda-forge tensorflow 6) 现在你可以进入 python 并处理 tensorflow (tensorflow)C:> python

7) But if you like to work on Tensorflow on Jupyter notebook you need to setup the karnel for your virtual environment in following steps: a) Install the ipython kernel module into your virtualenv

7) 但是如果你喜欢在 Jupyter notebook 上使用 Tensorflow,你需要按照以下步骤为你的虚拟环境设置 karnel:a) 将 ipython 内核模块安装到你的 virtualenv 中

activate your virtualenv, if you haven't already

激活你的 virtualenv,如果你还没有

pip install ipykernel

pip 安装 ipykernel

b) Now run the kernel "self-install" script: python -m ipykernel install --user --name=my-virtualenv-name

b) 现在运行内核“自安装”脚本: python -m ipykernel install --user --name=my-virtualenv-name

Replacing the --name parameter as appropriate. In my case it is tensorflow

根据需要替换 --name 参数。就我而言,它是张量流

c) You should now be able to see your kernel in the IPython notebook menu: Kernel -> Change kernel and be able so switch to it (you may need to refresh the page before it appears in the list). IPython will remember which kernel to use for that notebook from then on.

c) 您现在应该能够在 IPython notebook 菜单中看到您的内核:Kernel -> Change kernel 并能够切换到它(您可能需要在它出现在列表中之前刷新页面)。从那时起,IPython 将记住该笔记本使用哪个内核。

8) Test the tensorflow with following program you should see “Hello, TensorFlow!”

8) 使用以下程序测试 tensorflow,您应该会看到“Hello, TensorFlow!”

import tensorflow as tf

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

回答by Jibin Mathew

you can use pip to install tensorflow

您可以使用 pip 安装 tensorflow

  1. Install python 3.5 x64
  2. Install tensorflow using pip

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

  3. Install Visual C++ 2015 redistributable (x64 version) to be able to import tensorflow

  1. 安装 python 3.5 x64
  2. 使用 pip 安装 tensorflow

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

  3. 安装 Visual C++ 2015 redistributable (x64 version) 才能导入 tensorflow

回答by Prateek Dorwal

Tensorflow installation using Conda:

使用 Conda 安装 Tensorflow:

  1. Install Anaconda3-4.2.0 X64 (I ran into issue with latest release 4.3.0)
  2. Upgrade conda version 4.2.9-->4.2.11 (again, ran into some issues with conda 4.2.9)

    conda install conda=4.2.11

  3. create environment

    conda create -n tf python=3.5

  4. activate tf

  5. conda install -c conda-forge tensorflow

  1. 安装 Anaconda3-4.2.0 X64(我遇到了最新版本 4.3.0 的问题)
  2. 升级 conda 版本 4.2.9-->4.2.11(再次遇到 conda 4.2.9 的一些问题)

    conda 安装 conda=4.2.11

  3. 创造环境

    畅达创建 -n tf python=3.5

  4. 激活tf

  5. conda install -c conda-forge tensorflow

回答by dan diago

try installing tensorflow in conda

尝试在 conda 中安装 tensorflow

open anaconda prompt and type this

打开 anaconda prompt 并输入这个

conda install tensorflow

conda install tensorflow

回答by breizhmg

This worked for me (with spyder which is optional), typing in the anaconda prompt, on Windows 7:

这对我有用(使用 spyder 是可选的),在 Windows 7 上输入 anaconda 提示符:

conda create -n tensorflow pip python=3.5
conda activate tensorflow
pip install --ignore-installed --upgrade tensorflow 
conda install spyder
spyder

To exit the virtual environment:

退出虚拟环境:

conda deactivate

To restart the virtual environment:

要重新启动虚拟环境:

conda activate tensorflow
spyder