tensorflow 源码安装(for MacOS)
2018-02-05 11:00
369 查看
install tensorflow from sources for MacOS
运行tensorflow时经常遇到如下问题:
The TensorFlow library wasn’t compiled to use SSE4.1/SSE4.2 /AVX/AVX2/FMA instructions, but these are available on your machine and could speed up CPU computations
于是好奇就想尝试通过tensorflow源码安装解决这个问题
先说一下我的电脑系统版本:macOS sierra version 10.12.6 不带独显所以我装的是cpu版本的tensorflow
下面就是叙述一下安装步骤和我在安装过程中遇到的一些问题:
1. 先把tensorflow源码下载(clone the tensorflow repository)
$ git clone https://github.com/tensorflow/tensorflow
$ cd tensorflow
$ git checkout Branch # where
Branch is the desired branch
2. 配置环境(prepare environment for MacOS)
在安装tensorflow之前,必须先安装bazel和python依赖包(six numpy wheel)
利用homebrew安装bazel,先安装JDK 8和homebrew, 这两个我很早就安装了就不叙述了
利用brew安装bazel如下:
brew install bazel
bazel version
brew upgrade bazel
install python dependencies
pip install six numpy wheel
3. 配置安装tensorflow
前面下载的安装源里有一个bash 脚本文件:congigure
这个文件可以帮助你识别安装tensorflow所需包的路径等问题运行如下:在tensorflow路径,
tensorflow hfes$ ./configure
here is an example excution of the configure script:
You have bazel 0.10.0-homebrew installed.
Please specify the location of python. [Default is /Users/bingxueguo/anaconda/bin/python]: /Users/bingxueguo/anaconda/bin/python
Found possible Python library paths:
/Users/bingxueguo/anaconda/lib/python3.5/site-packages
Please input the desired Python library path to use.
Default is [/Users/bingxueguo/anaconda/lib/python3.5/site-packages]
/Users/bingxueguo/anaconda/lib/python3.5/site-packages
Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: Y
Google Cloud Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: Y
Hadoop File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: Y
Amazon S3 File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Apache Kafka Platform support? [y/N]: Y
Apache Kafka Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with XLA JIT support? [y/N]: Y
XLA JIT support will be enabled for TensorFlow.
Do you wish to build TensorFlow with GDR support? [y/N]: Y
GDR support will be enabled for TensorFlow.
Do you wish to build TensorFlow with VERBS support? [y/N]: n
No VERBS support
4000
will be enabled for TensorFlow.
Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: N
No OpenCL SYCL support will be enabled for TensorFlow.
Do you wish to build TensorFlow with CUDA support? [y/N]: N
No CUDA support will be enabled for TensorFlow.
Do you wish to build TensorFlow with MPI support? [y/N]: N
No MPI support will be enabled for TensorFlow.
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: -march=native
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: N
Not configuring the WORKSPACE for Android builds.
Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See tools/bazel.rc for more details.
--config=mkl
# Build with MKL support.
--config=monolithic
# Config for mostly static monolithic build.
--config=tensorrt
# Build with TensorRT support.
Configuration finished
前面的选择Y/N会影响到之后的安装是否出现问题,
一开始我在这里选择了一个y
Do you wish to build TensorFlow with VERBS support? [y/N]: n
No VERBS support will be enabled for TensorFlow.
后面出现了如下问题:
./tensorflow/contrib/verbs/rdma.h:21:10:
fatal error: 'infiniband/verbs.h' file not found
#include <infiniband/verbs.h> ^~~~~~~~~~~~~~~~~~~~
1 error generated.
也是搜索查询了好久很多给的是linux的解决办法,于是我又重新运行./configure选择了n才解决。
4.编译目标程序(这个只要前面配置没什么问题基本到这一步不会出什么问题,只是时间得一二十分钟)
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
运行这一步后也会产生一个tensorflow的安装包(.whl)在文件夹
/tmp/tensorflow_pkg/下面
5. 安装pip包
官网上给的是
当然这个包的名称还是要根据自己前面运行生成的,由于我也是初接触这些,也是琢磨了一下,发现直接在网页里输入
///tmp/tensorflow_pkg/ 可以找到前面生成的安装包,下载下来放在对应的文件夹然后用pip 安装即可
pip install tensorflow-1.5.0-cp35-cp35m-macosx_10_6_x86_64.whl
现在运行这个就不会出现一开始提到的问题了:
>>> import tensorflow as tf
>>> hello = tf.constant("Hello,Tensorflow")
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello,Tensorflow'
运行速度也会加快
运行tensorflow时经常遇到如下问题:
The TensorFlow library wasn’t compiled to use SSE4.1/SSE4.2 /AVX/AVX2/FMA instructions, but these are available on your machine and could speed up CPU computations
于是好奇就想尝试通过tensorflow源码安装解决这个问题
先说一下我的电脑系统版本:macOS sierra version 10.12.6 不带独显所以我装的是cpu版本的tensorflow
下面就是叙述一下安装步骤和我在安装过程中遇到的一些问题:
1. 先把tensorflow源码下载(clone the tensorflow repository)
$ git clone https://github.com/tensorflow/tensorflow
$ cd tensorflow
$ git checkout Branch # where
Branch is the desired branch
2. 配置环境(prepare environment for MacOS)
在安装tensorflow之前,必须先安装bazel和python依赖包(six numpy wheel)
利用homebrew安装bazel,先安装JDK 8和homebrew, 这两个我很早就安装了就不叙述了
利用brew安装bazel如下:
brew install bazel
bazel version
brew upgrade bazel
install python dependencies
pip install six numpy wheel
3. 配置安装tensorflow
前面下载的安装源里有一个bash 脚本文件:congigure
这个文件可以帮助你识别安装tensorflow所需包的路径等问题运行如下:在tensorflow路径,
tensorflow hfes$ ./configure
here is an example excution of the configure script:
You have bazel 0.10.0-homebrew installed.
Please specify the location of python. [Default is /Users/bingxueguo/anaconda/bin/python]: /Users/bingxueguo/anaconda/bin/python
Found possible Python library paths:
/Users/bingxueguo/anaconda/lib/python3.5/site-packages
Please input the desired Python library path to use.
Default is [/Users/bingxueguo/anaconda/lib/python3.5/site-packages]
/Users/bingxueguo/anaconda/lib/python3.5/site-packages
Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: Y
Google Cloud Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: Y
Hadoop File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: Y
Amazon S3 File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Apache Kafka Platform support? [y/N]: Y
Apache Kafka Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with XLA JIT support? [y/N]: Y
XLA JIT support will be enabled for TensorFlow.
Do you wish to build TensorFlow with GDR support? [y/N]: Y
GDR support will be enabled for TensorFlow.
Do you wish to build TensorFlow with VERBS support? [y/N]: n
No VERBS support
4000
will be enabled for TensorFlow.
Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: N
No OpenCL SYCL support will be enabled for TensorFlow.
Do you wish to build TensorFlow with CUDA support? [y/N]: N
No CUDA support will be enabled for TensorFlow.
Do you wish to build TensorFlow with MPI support? [y/N]: N
No MPI support will be enabled for TensorFlow.
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: -march=native
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: N
Not configuring the WORKSPACE for Android builds.
Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See tools/bazel.rc for more details.
--config=mkl
# Build with MKL support.
--config=monolithic
# Config for mostly static monolithic build.
--config=tensorrt
# Build with TensorRT support.
Configuration finished
前面的选择Y/N会影响到之后的安装是否出现问题,
一开始我在这里选择了一个y
Do you wish to build TensorFlow with VERBS support? [y/N]: n
No VERBS support will be enabled for TensorFlow.
后面出现了如下问题:
./tensorflow/contrib/verbs/rdma.h:21:10:
fatal error: 'infiniband/verbs.h' file not found
#include <infiniband/verbs.h> ^~~~~~~~~~~~~~~~~~~~
1 error generated.
也是搜索查询了好久很多给的是linux的解决办法,于是我又重新运行./configure选择了n才解决。
4.编译目标程序(这个只要前面配置没什么问题基本到这一步不会出什么问题,只是时间得一二十分钟)
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
运行这一步后也会产生一个tensorflow的安装包(.whl)在文件夹
/tmp/tensorflow_pkg/下面
5. 安装pip包
官网上给的是
sudo pip install /tmp/tensorflow_pkg/tensorflow-1.5.0-py2-none-any.whl
当然这个包的名称还是要根据自己前面运行生成的,由于我也是初接触这些,也是琢磨了一下,发现直接在网页里输入
///tmp/tensorflow_pkg/ 可以找到前面生成的安装包,下载下来放在对应的文件夹然后用pip 安装即可
pip install tensorflow-1.5.0-cp35-cp35m-macosx_10_6_x86_64.whl
现在运行这个就不会出现一开始提到的问题了:
>>> import tensorflow as tf
>>> hello = tf.constant("Hello,Tensorflow")
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello,Tensorflow'
运行速度也会加快
相关文章推荐
- 安装Oracle JDK 7.0与8.0 for Mac OS X后Eclipse启动报错的解决之道
- Mac OS X下安装配置Android源码开发环境
- 在 Mac OS X 上安装 TensorFlow
- mac源码安装tensorflow
- Mac下使用源码编译安装TensorFlow CPU版本
- 解决Virtual Box 下安装Mac OS X时出现的“hfs: could not initializc summary table for OSX Base System ”问题
- 在 Mac OS X 上安装 TensorFlow
- 解决近期Mac无法安装docker-compose的问题(docker compose installation for OS X EI Capitan)
- TensorFlow 安装官方教程:Ubuntu 安装,Mac OS X 安装,Windows 安装
- 在mac osX下安装openCV,used for python
- Mysql&nbsp;for&nbsp;MacOSX&nbsp;安装和基本操作
- 在dell dimension 5150 上安装mac os x for pc 10.4.8 手记 1] 网卡的安装
- Mac OS X 下源码安装MySQL 5.7
- 在dell dimension 5150 上安装mac os x for pc 10.4.8 手记 2] 声卡的安装
- 在Mac OS X上安装TensorFlow
- OpenCV for mac install(一)源码安装
- MacOS Lion 安装MySQLdb for python 遇到的问题
- Mac OS X 下安装 TensorFlow
- 安装Oracle JDK 7.0与8.0 for Mac OS X后Eclipse启动报错的解决之道
- 在dell dimension 5150 上安装mac os x for pc 10.4.8 手记 3] 显卡的安装