简体   繁体   English

为什么使用Anaconda环境在Windows上安装tensorflow?

[英]Why using Anaconda environments to install tensorflow on Windows?

In tensorflow installation guide it is said, that I should use "environment" to install tensorflow: https://www.tensorflow.org/install/install_windows#installing_with_anaconda在 tensorflow 安装指南中说,我应该使用“环境”来安装 tensorflow: https ://www.tensorflow.org/install/install_windows#installing_with_anaconda

Why?为什么? Can't I just install with pip?我不能只用pip安装吗?

If installed with environment, should I "activate" it each time I use tensorflow?如果安装了环境,我是否应该在每次使用tensorflow时“激活”它?

If I use tensorflow from within other thing like keras and/or PyCharm, then how can I activate environment?如果我从 keras 和/或 PyCharm 等其他东西中使用 tensorflow,那么我该如何激活环境?

The question is about Windows.问题是关于 Windows 的。 I assume you installed python using anaconda.我假设你使用 anaconda 安装了 python。 Then you have a default environment, called root.然后你有一个默认环境,称为 root。 You can create as many environments as you want, think of each as a separate installation of python.您可以根据需要创建任意数量的环境,将每个环境视为 python 的单独安装。 Using conda or pip installs stuff at your current installation.使用 conda 或 pip 在您当前的安装中安装东西。 Conda stuff is kind of pre-compiled to work with your machine/anaconda environment, while pip stuff is usually compiled on the spot. Conda 的东西是预编译的,可以与您的机器/anaconda 环境一起使用,而 pip 的东西通常是当场编译的。 I assume compiling tensorflow might not be completely trivial...我假设编译 tensorflow 可能不是完全微不足道的......

'Activate' changes from one environment to the other, so unless you have multiple environments you shouldn't need it. “激活”从一个环境更改为另一个环境,因此除非您有多个环境,否则您不需要它。 You run all these on command prompt.您在命令提示符下运行所有这些。

Bottom line is, unless you have multiple environments (I highly recommend it so you can try different things) I cannot see you using activate.底线是,除非你有多个环境(我强烈推荐它,这样你可以尝试不同的东西)我看不到你使用激活。 Install tensorflow and keras on the same one and only root environment you have.在您拥有的同一个且唯一的根环境中安装 tensorflow 和 keras。 You should be able to access both (it is also possible just installing keras would install tensorflow, if its a dependancy)你应该能够访问两者(如果它是一个依赖项,也可以只安装 keras 就安装 tensorflow)

If you see no prompt, it is the default, root environment.如果您没有看到任何提示,则这是默认的根环境。 You can see all your environments with: conda info --envs But unless you create some environment (using eg conda create --name py Python=2) you probably only have root.您可以使用以下命令查看所有环境:conda info --envs 但是除非您创建一些环境(例如使用 conda create --name py Python=2),否则您可能只有 root。 One of the nice things with environments is you can have one with Python=2 (latest python 2), one with Python=3, another with Python=2.7 etc环境的好处之一是您可以拥有一个 Python=2(最新的 python 2),一个 Python=3,另一个 Python=2.7 等

On your follow-up, If you have multiple environments, you can switch between them on Pycharm by changing the interpreter.在您的后续行动中,如果您有多个环境,您可以通过更改解释器在 Pycharm 上在它们之间切换。 On the image you see me selecting eg py2_olv在图像上,您看到我选择了例如 py2_olv 在此处输入图像描述

Professional answer:专业解答:

Quote from https://machinelearningspace.com/installing-tensorflow-2-0-in-anaconda-environment/ :引自https://machinelearningspace.com/installing-tensorflow-2-0-in-anaconda-environment/

What is Anaconda and why I recommend it?什么是 Anaconda,我为什么推荐它?

... [dropped intro to Anaconda]... ... [放弃对 Anaconda 的介绍]...

For a Python developer or a data science researcher, using Anaconda has a lot of advantages, such as independently installing/updating packages without ruining the system.对于 Python 开发人员或数据科学研究人员来说,使用 Anaconda 有很多优势,例如独立安装/更新包而不会破坏系统。 So, we no need to worry about the system library or anything like that.因此,我们无需担心系统库或类似的东西。 This can save time and energy for other things.这可以为其他事情节省时间和精力。

Anaconda can be used across different platforms, Windows, macOS, and Linux. Anaconda 可以跨不同的平台使用,Windows、macOS 和 Linux。 If we want to use a different Python version or package libraries, just create a different environment and play around without any risk of crashing the system library.如果我们想使用不同的 Python 版本或包库,只需创建一个不同的环境并在没有任何崩溃系统库的风险的情况下进行尝试。

#### Unprofessional research: #### 非专业研究:

Now in addition my own research.现在加上我自己的研究。 I am not a professional, I have little knowledge of the seemingly chaotic world of different install methods.我不是专业人士,我对不同安装方法看似混乱的世界知之甚少。 This refers to some first research at https://superuser.com/questions/1572640/do-i-need-to-install-cuda-separately-after-installing-the-nvidia-display-driver/1572762#1572762 .这是指https://superuser.com/questions/1572640/do-i-need-to-install-cuda-separately-after-installing-the-nvidia-display-driver/1572762#1572762上的一些初步研究。 Mind that I am guessing a lot here.请注意,我在这里猜测了很多。 Please comment if I am wrong.如果我错了,请发表评论。

We see that at the moment, Pytorch supports version 10.2, Tensorflow supports 10.1, and it is not just the version that differs: mind that "CUDA Toolkit" (standalone) and cudatoolkit (conda binary install) are different, One is aa standalone / executable install.我们看到目前Pytorch支持10.2版本,Tensorflow支持10.1版本,不只是版本不同:注意“CUDA Toolkit”(standalone)和cudatoolkit(conda binary install)是不同的,一个是aa standalone /可执行安装。 the other is a binary install.另一个是二进制安装。 And tensorflow needs tensorflow-gpu to reach the standalone cuda install.并且 tensorflow 需要 tensorflow-gpu 来实现独立的 cuda 安装。

Therefore you should consider a separate environment for both Tensorflow and Pytorch, since any update of the conda cudatoolkit to version 11.0 could harm the dependency condition of Pytorch (Though this is not completely right. Pytorch uses a cuda that is installed inside Pytorch. It is still the approach to understand the recommended different envs).因此,您应该为 Tensorflow 和 Pytorch 考虑一个单独的环境,因为将 conda cudatoolkit 更新到版本 11.0 可能会损害 Pytorch 的依赖条件(尽管这不完全正确。Pytorch 使用安装在 Pytorch 内部的 cuda。它是仍然是理解推荐的不同环境的方法)。 For tensorflow, you have to install version CUDA Toolkit 10.1 although 11.0 is already available, so that your whole card must run on a lower version than possible only to support Tensorflow - even if some games would like to have version 11.0.对于 tensorflow,您必须安装 CUDA Toolkit 10.1 版本,尽管 11.0 版本已经可用,因此您的整个卡必须运行在低于可能仅支持 Tensorflow 的版本上 - 即使某些游戏希望拥有 11.0 版本。

Unprofessional answer:不专业的回答:

If all of the dependencies are so important and so easily wrong when updated separately, like you could do with pip, any install that you do by yourself using pip might crash your sensitive tensorflow install.如果所有的依赖项都非常重要,并且在单独更新时很容易出错,就像您可以使用 pip 那样,那么您使用 pip 自己进行的任何安装都可能会导致敏感的 tensorflow 安装崩溃。 Therefore it is recommended to keep to a full service approach which Anaconda offers, where all dependencies are kept right, even if you enter conda install --all .因此,建议保持 Anaconda 提供的完整服务方法,其中所有依赖项都保持正确,即使您输入conda install --all也是如此。 That is why you better search for an Anaconda guide, for example https://machinelearningspace.com/installing-tensorflow-2-0-in-anaconda-environment/ .这就是为什么您最好搜索 Anaconda 指南,例如https://machinelearningspace.com/installing-tensorflow-2-0-in-anaconda-environment/

If you would have read through the entire document, it would have stated that the Anaconda installation is community supported, not officially supported.如果您通读了整个文档,它会说明 Anaconda 安装是社区支持的,而不是官方支持的。 They want you to install TensorFlow using native pip through Python 3.5.x.他们希望您通过 Python 3.5.x 使用本机 pip 安装 TensorFlow。 That being said, from personal experience, I will tell you that if you are looking to run basic level TensorFlow Python scripts, such as training and testing an MNIST model, a Windows installation will be fine, or using a model that has already been trained for some purpose will also be fine.话虽这么说,根据个人经验,我会告诉你,如果你想运行基本级别的 TensorFlow Python 脚本,例如训练和测试 MNIST 模型,Windows 安装会很好,或者使用已经训练过的模型出于某种目的也可以。 However, if you want to train advanced models such as Inception, which are the state-of-the-art image classifiers with less than 5% error for normal images, Windows is not suitable.但是,如果你想训练高级模型,如 Inception,这是最先进的图像分类器,对正常图像的错误率低于 5%,Windows 不适合。 You should try using Linux installation for any training purposes.您应该尝试将 Linux 安装用于任何培训目的。 I would recommend using VirtualBox, having used it in the past.我会推荐使用 VirtualBox,过去使用过它。 As for activating the environment, as long as, in any script / in the bash, you include the line "import tensorflow as tf", you should be fine, at least for native pip installation.至于激活环境,只要在任何脚本/bash 中包含“import tensorflow as tf”行,就应该没问题,至少对于本机 pip 安装是这样。 Good luck!祝你好运!

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

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