Mac使用pip安装Tensorflow

原文链接:http://www.cnblogs.com/tensorflownews/p/7298646.html

Mac 使用本地 pip 安装Tensorflow

我们已经将 TensorFlow 二进制文件上传到了 PyPI,因此你可以通过 pip 安装, REQUIRED_PACKAGES section of setup.py 文件列出了 pip 将要安装或升级的包。

必备: Python

要安装 TensorFlow,你的系统必须依据安装了以下任一 Python 版本:

  • Python 2.7,建议首先更新最新的Python2.7,我使用的是Python2.7,点击这里下载最新版
  • Python 3.3+

如果你的系统还没有安装符合以上版本的 Python,现在安装

安装 Python,你可能需要禁用系统完整性保护(SIP)来获得从 Mac App Store 外安装软件的许可。

必备: pip

Pip 安装和管理 Python写的软件包,如果你要使用本地 pip 安装,系统上必须安装下面的任一 pip 版本:

  • pip, for Python 2.7
  • pip3, for Python 3.n.

pip 或者 pip3 可能在你安装 Python 的时候已经安装了,执行以下任一命令确认系统上是否安装了 pip 或 pip3:

$ pip -V  # for Python 2.7
$ pip3 -V # for Python 3.n 

我们强烈建议使用 pip 或者 pip3 为 8.1 或者更新的版本安装 TensorFlow,如果没有安装,执行以下任一命令安装或更新:

$ sudo easy_install --upgrade pip
$ sudo easy_install --upgrade six 

安装 TensorFlow

假设你的 Mac 上已经装好了必备的程序,按照以下步骤执行:

  1. 执行以下任一命令安装 TensorFlow:

shell $ pip install tensorflow # Python 2.7; CPU support $ pip3 install tensorflow # Python 3.n; CPU support

如果上面的命令执行完成,现在可以验证你的安装了。

  1. (可选的) 如果步骤 1 失败了,执行下面的命令安装最新版本 TensorFlow:

shell $ sudo pip install --upgrade tfBinaryURL # Python 2.7 $ sudo pip3 install --upgrade tfBinaryURL # Python 3.n

tfBinaryURL 是 Tensorflow 包的 URL,准确的 tfBinaryURL 值因操作系统和 Python 版本而异,在这里找到和你系统相关的 tfBinaryURL 值。例如,你要在 Mac OS X 上安装 Python 2.7 对应的 Tensorflow 版本,在虚拟环境中安装 Tensorflow 就执行下面的命令:

shell $ sudo pip3 install --upgrade \ https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.2.1-py2-none-any.whl

Exception

DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.

Uninstalling six-1.4.1:

Exception:

Traceback (most recent call last):

File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main

status = self.run(options, args)

File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run

prefix=options.prefix_path,

File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 778, in install

requirement.uninstall(auto_confirm=True)

File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 754, in uninstall

paths_to_remove.remove(auto_confirm)

File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove

renames(path, new_path)

File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 267, in renames

shutil.move(old, new)

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move

copy2(src, real_dst)

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2

copystat(src, dst)

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat

os.chflags(dst, st.st_flags)

OSError: [Errno 1] Operation not permitted: '/tmp/pip-mUKyli-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

sudo pip install --upgrade --ignore-installed six

DEPRECATION: Uninstalling a distutils installed project (numpy) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.

Exception:

Traceback (most recent call last):

File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main

status = self.run(options, args)

File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run

prefix=options.prefix_path,

File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 778, in install

requirement.uninstall(auto_confirm=True)

File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 754, in uninstall

paths_to_remove.remove(auto_confirm)

File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove

renames(path, new_path)

File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 267, in renames

shutil.move(old, new)

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move

copy2(src, real_dst)

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2

copystat(src, dst)

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat

os.chflags(dst, st.st_flags)

OSError: [Errno 1] Operation not permitted: '/tmp/pip-I9uezC-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy-1.8.0rc1-py2.7.egg-info'

sudo pip install --upgrade --ignore-installed numpy