简体   繁体   English

在 conda 环境中安装 Tensorflow 2.0

[英]Install Tensorflow 2.0 in conda enviroment

I would like to know if anyone knows how can I install tensorflow==2.0.0-alpha0 in a conda enviroment using python 3.7.我想知道是否有人知道如何使用 python 3.7 在 conda 环境中安装 tensorflow==2.0.0-alpha0。 Is it possible to use python 3.7 or do I have to downgrade to 3.6.是否可以使用 python 3.7 或者我必须降级到 3.6。 Either way what is the command I need to use because the following don't find any package无论哪种方式,我需要使用什么命令,因为以下找不到任何包

conda install tensorflow==2.0.0-alpha0
conda install tensorflow 
conda install tensorflow=2.0.0-alpha0

I am using fedora 29 and conda 4.6.8 Thanks!我使用的是 Fedora 29 和 conda 4.6.8 谢谢!

TENSORFLOW 2.0 release version is out! TENSORFLOW 2.0 发布版本发布了!

Since 01/10/2019 I'm not talking beta but the release version.自 2019 年 1 月 10 日起,我不是在谈论测试版,而是在发布版本。

Using Anaconda使用蟒蛇

Since 01/11/2019 Anaconda is supporting the Tensorflow 2.0.0.自 2019 年 1 月 11 日起,Anaconda 开始支持 Tensorflow 2.0.0。

Option 1: For what the easiest way is just:选项 1:对于最简单的方法是什么:

conda install tensorflow or conda install tensorflow-gpu conda install tensorflowconda install tensorflow-gpu

For the gpu mode, anaconda will take care of all the CUDA everything you need to install for the tensorflow gpu mode to work so I strongly recommend using this method.对于 gpu 模式,anaconda 会处理所有您需要安装的 CUDA 以便 tensorflow gpu 模式工作,因此我强烈建议使用此方法。

The only issue with this method is that anaconda might not have the last last version of TensorFlow.这种方法的唯一问题是 anaconda 可能没有 TensorFlow 的最后一个版本。 For example, at Feb 21 2021, conda has the version 2.3 whereas the PIP version is 2.4.例如,在 2021 年 2 月 21 日,conda 的版本为 2.3,而 PIP 版本为 2.4。 You can check the current version of gpu or cpu .您可以检查gpucpu的当前版本。

Option 2 (virtual env): It is strongly recommended to use an environment on where to install tensorflow, for which you need the following command that will create an environment first and then install tensorflow within:选项 2(虚拟 env): 强烈建议在安装 tensorflow 的位置使用环境,为此您需要以下命令先创建一个环境,然后在其中安装 tensorflow:

  • CPU: conda create -n <your_env_name> tensorflow CPU: conda create -n <your_env_name> tensorflow
  • GPU : conda create -n <your_env_name> tensorflow-gpu GPUconda create -n <your_env_name> tensorflow-gpu

Change <your_env_name> by a meaningful name like tf-2<your_env_name>更改为有意义的名称,例如tf-2

To use tensorflow run first conda activate <your_env_name>要使用 tensorflow 首先运行conda activate <your_env_name>

Using pip使用点子

Using pip the tensorflow official instructions are quite complete.使用 pip tensorflow官方说明已经很完整了。

Just install tensorflow using pip like:只需使用 pip 安装 tensorflow,例如:

# Current stable release for CPU-only
pip install tensorflow

I yet recommend before doing everything to install tensorflow in a new environment so the 3 steps would be (with anaconda):我还建议在做任何事情之前在新环境中安装 tensorflow,所以 3 个步骤是(使用 anaconda):

conda create --n <our_env_name> pip
conda activate <your_env_name>
pip install tensorflow

Now for the GPU version it's harder with pip, I recommend you this link that explains the extra things you need to install (CUDA and others).现在对于 GPU 版本,使用 pip 更难,我向您推荐此链接,该链接解释了您需要安装的额外内容(CUDA 和其他)。

It could be the case that the package version you want is not available in conda-forge.可能是您想要的软件包版本在 conda-forge 中不可用。 What you could do is install packages with pip in your conda environment.您可以做的是在 conda 环境中使用 pip 安装软件包。

pip install tensorflow==2.0.0-alpha0 

Also the requirements don't state python 3.7, you can try your luck or downgrade to python 3.6.此外,要求没有说明python 3.7,您可以试试运气或降级到python 3.6。

You can now install TF2 for Python 3.7 using conda.您现在可以使用 conda 为 Python 3.7 安装 TF2。 You can run the usual你可以运行通常的

$ conda install tensorflow=2.0 python=3.7

or或者

$ conda install tensorflow-gpu=2.0 python=3.7

for the GPU version.对于 GPU 版本。

My preferred approach however would be to manage the dependencies using an environment.yml file.然而,我的首选方法是使用environment.yml文件管理依赖项。 You can find examples of how to do this for TF2 and dependencies in these template repos that I created on GitHub.您可以在我在 GitHub 上创建的这些模板存储库中找到有关如何为 TF2 和依赖项执行此操作的示例。

https://github.com/kaust-vislab/tensorflow-cpu-data-science-project https://github.com/kaust-vislab/tensorflow-cpu-data-science-project

https://github.com/kaust-vislab/tensorflow-gpu-data-science-project https://github.com/kaust-vislab/tensorflow-gpu-data-science-project

The problem is in conda install tensorflow .问题在于conda install tensorflow

conda does not have tensorflow . conda没有tensorflow You will require to install tensorflow using pip .您将需要使用pip安装tensorflow You do not need to downgrade your Python.并不需要降级你的Python。 It will work with Python 3.7.它将与 Python 3.7 一起使用。

Use this用这个

$ pip install --upgrade tensorflow==2.0.0-beta0

Since the beta0 version is released, I mentioned that.由于beta0版本发布,我提到了这一点。 You can choose other tf version.您可以选择其他 tf 版本。

I recommend going through this post on TowardsDataScience: Step-by-Step Guide to Install Tensorflow 2.0 .我建议阅读 TowardsDataScience: Step-by-Step Guide to Install Tensorflow 2.0上的这篇文章。

This post covers installation steps with conda .这篇文章介绍了conda安装步骤。

You might want to take a look at this link: https://pypi.org/project/tf-nightly-2.0-preview/#files to see which python version and OS supports your package您可能想查看此链接: https : //pypi.org/project/tf-nightly-2.0-preview/#files以查看哪个 python 版本和操作系统支持您的包

在此处输入图片说明

I tried to install tensorflow v2 with conda install tensorflow or conda install tensorflow-gpu only to get lots of incompatible dependencies.我尝试使用 conda conda install tensorflowconda install tensorflow-gpu安装 tensorflow v2 只是为了获得许多不兼容的依赖项。

Just run赶紧跑

pip install -upgrade tensorflow-gpu

or或者

pip install tensorflow-gpu=2.0.0 for a specific version pip install tensorflow-gpu=2.0.0指定版本

Use ' pip3 install tensorflow-gpu '.使用“pip3 install tensorflow-gpu”。 This command does the job - downloads Tensorflow-gpu = 2.4.1此命令完成工作 - 下载 Tensorflow-gpu = 2.4.1

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

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