简体   繁体   English

如何在Mac或Linux上安装tensorflow 2.0?

[英]How to install tensorflow 2.0 on Mac or Linux?

TensorFlow 2.0 is released recently. TensorFlow 2.0 最近发布。 There are no clear steps on how to install it.没有关于如何安装它的明确步骤。 Any help with the steps for installation is appreciated.对安装步骤的任何帮助表示赞赏。

Four other developers have the same problem.其他四位开发人员也有同样的问题。 The last comment is June 3rd.最后一条评论是 6 月 3 日。 I eventually sent emails to all the email addresses of the contributors I could find listed at https://github.com/apple/tensorflow_macos , but none of them replied.我最终向https://github.com/apple/tensorflow_macos 中列出的所有贡献者的电子邮件地址发送了电子邮件,但他们都没有回复。 The repository is now read-only, and archived, allowing no more comments.该存储库现在是只读的,并已存档,不允许再发表评论。 https://github.com/apple is Apple's official github page. https://github.com/apple是 Apple 的官方 github 页面。

The world's first trillion-dollar company is unable to support one of its claims about its new computer - that it can be used to do machine learning in Python using Tensorflow.世界上第一家价值数万亿美元的公司无法支持其关于其新计算机的一项声明——它可以使用 Tensorflow 在 Python 中进行机器学习。 Contrast this with my experience of the open-source programming language Elixir.将此与我对开源编程语言 Elixir 的体验进行对比。 Every question I have asked at https://elixirforum.com/ got answered within 24 hours by the creator of the language, Jose Valim.我在https://elixirforum.com/ 上提出的每个问题都在 24 小时内得到了该语言的创建者 Jose Valim 的回答。

Emmmm, actually is quite easy, though the tensorflow 2.0 is still in experimental stage. Emmmm,其实很简单,虽然tensorflow 2.0还处于实验阶段。 It is better to install the preview version in a virtual environment with anaconda, now the following is a Linux example:最好用anaconda在虚拟环境中安装preview version ,现在以Linux为例:

$ conda create --name tensorflow_2_0
$ conda activate tensorflow_2_0
$ pip install tf-nightly-2.0-preview # tf-nightly-gpu-2.0-preview for GPU version

Now let's have a try:现在让我们试一试:

$ ipython # or ipython3/python/python3(at least one of which will work)
>>> import tensorflow as tf
>>> print(tf.__version__)
2.0.0-dev20190129

Done.完毕。

----------------2019.10.01 Update--------------- ----------------2019.10.01 更新--------------
Today, the official tensorflow 2.0.0 is published.今天,官方发布了tensorflow 2.0.0。 You can find how to install it here .您可以在此处找到如何安装它。
Simply, still activate your conda virtual environment and upgrade your pip first with:简单地说,仍然activate您的 conda 虚拟环境并首先使用以下命令升级您的pip

pip install --upgrade pip

Then upgrade your tensorflow directly to 2.0.0:然后将你的 tensorflow 直接升级到 2.0.0:

pip install --upgrade tensorflow  # tensorflow-gpu for gpu verison

Finally:最后:

>>> import tensorflow as tf
>>> tf.__version__
'2.0.0'

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 (Recommended)使用 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 模式工作,因此我强烈建议使用此方法。

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现在对于 GPU 版本,pip 更难,我推荐你这个链接

Thanks for this.谢谢你。 I tried following the latest instructions.我尝试按照最新的说明进行操作。

Following the instructions at https://github.com/apple/tensorflow_macos In the Terminal on a new Mac M1:按照https://github.com/apple/tensorflow_macos在新 Mac M1 上的终端中的说明进行操作:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apple/tensorflow_macos/master/scripts/download__install.sh)"

Confirm y/N?确认是/否? y Installing and upgrading base packages. y 安装和升级基础包。

Then it says然后它说

TensorFlow and TensorFlow Addons with ML Compute for macOS 11.0 successfully installed. TensorFlow 和 TensorFlow Addons with ML Compute for macOS 11.0 已成功安装。 To begin, activate the virtual environment:首先,激活虚拟环境:

. "/private/var/folders/6c/56kflzvn7vzcm7vx4kpnw0d00000gn/T/tmp.TNKnwmCZ/tensorflow_macos/tensorflow_macos_venv/bin/activate"

Below /private/var/folders/6c/56kflzvn7vzcm7vx4kpnw0d00000gn/T, the next folder, tmp.TNKnwmCZ, does not exist and /private is owned by root, so executing anything inside it, even if it does exist, requires 'sudo'在 /private/var/folders/6c/56kflzvn7vzcm7vx4kpnw0d00000gn/T 下,下一个文件夹 tmp.TNKnwmCZ 不存在并且 /private 归 root 所有,因此执行其中的任何内容,即使它确实存在,也需要“sudo”

Trying the other way of installing Tensorflow given at https://github.com/apple/tensorflow_macos尝试在https://github.com/apple/tensorflow_macos 上给出的另一种安装 Tensorflow 的方法

curl -fLO https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha2/tensorflow_macos-${VERSION}.tar.gz
tar xvzf tensorflow_macos-${VERSION}.tar
cd tensorflow_macos
./install_venv.sh --prompt

It's not clear what VERSION is supposed to be, and https://github.com/apple/tensorflow_macos/releases/download/ does not exist, so the first of the above commands fails, whatever you set VERSION to目前尚不清楚 VERSION 应该是什么,并且https://github.com/apple/tensorflow_macos/releases/download/不存在,因此无论您将 VERSION 设置为什么,上述第一个命令都会失败

Trying another way: git clone https://github.com/apple/tensorflow_macos尝试另一种方式:git clone https://github.com/apple/tensorflow_macos

cd tensorflow_macos/scripts

./download_and_install.sh 

It tells you to run它告诉你跑

. "/private/var/folders/6c/56kflzvn7vzcm7vx4kpnw0d00000gn/T/tmp.xVyjLM93/tensorflow_macos/activate"

and again, these folders only exist down to T, and they are all owned by root再说一次,这些文件夹只存在于 T,它们都归 root 所有


So I tried the method recommended above - conda install tensorflow于是我尝试了上面推荐的方法conda install tensorflow

I found the conda executable in /opt/homebrew/anaconda3/bin我在 /opt/homebrew/anaconda3/bin 中找到了 conda 可执行文件

conda install tensorflow

It failed because它失败了,因为

  • tensorflow -> python[version='2.7.张量流-> python[版本=‘2.7。 |3.7. |3.7。 |3.6. |3.6. |3.5. |3.5。 '] ']

Your python: python=3.8你的蟒蛇:python=3.8

Apple insists that their tensorflow depends on Python 3.8 https://github.com/apple/tensorflow_macos Apple 坚持认为他们的 tensorflow 依赖于 Python 3.8 https://github.com/apple/tensorflow_macos

In case you are struggling to install Tensorflow on a mac M1 computer, I highly recommend taking a look at this.如果您在 Mac M1 计算机上安装 Tensorflow 时遇到困难,我强烈建议您看看这个。 It works like a charm: https://www.mrdbourke.com/setup-apple-m1-pro-and-m1-max-for-machine-learning-and-data-science/它就像一个魅力: https://www.mrdbourke.com/setup-apple-m1-pro-and-m1-max-for-machine-learning-and-data-science/

For anyone still struggling with installing Tensorflow>=2.0 on MacOS, I was able to do the following:对于仍在努力在 MacOS 上安装 Tensorflow>=2.0 的任何人,我能够执行以下操作:

pip install tensorflow-macos

Make sure you have the latest Numpy version though, otherwise you might run into other problems:确保你有最新的 Numpy 版本,否则你可能会遇到其他问题:

pip install numpy --upgrade

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

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