=VMWare+Ubuntu+Tensorflow===
VMWare + Ubuntu16.0.4
VMWare Player不支持GPU,只能安装CPU版本
自带-Python2.7.12
Bazel如下0.18-1
Tensorflow-master1.12 (2018/11/06下载)
https://www.tensorflow.org/install/source
0. 安装依耐项
sudo apt install python-dev python-pip # or python3-dev python3-pip
pip install -U --user pip six numpy wheel mock
pip install -U --user keras_applications1.0.5 --no-deps
pip install -U --user keras_preprocessing1.0.3 --no-deps
- Bazel安装
https://docs.bazel.build/versions/master/install-ubuntu.html
1.1 下载sh安装文件
https://github.com/bazelbuild/bazel/releases
bazel-0.18.1-installer-linux-x86_64.sh
sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python
chmod +x bazel-0.18.1-installer-linux-x86_64.sh
./bazel-0.18.1-installer-linux-x86_64.sh --user
安装在个人目录下面
The --user flag installs Bazel to the $HOME/bin directory on your system and sets the .bazelrc path to $HOME/.bazelrc.
1.2 增加环境变量
export PATH=“
P
A
T
H
:
PATH:
PATH:HOME/bin”
-
下载源码
https://github.com/tensorflow/tensorflow.git
=> 直接用master
=> release版本在PC-Window上编译不过,VMWare上没有试过
2.1 解压 => tensorflow -
Tensorflow源码编译配置
./configure
=> 根据实际情况配置 -
CPU-Only编译
4.1 编译命令
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
4.2 编译问题
ERROR: /home/xhu/.cache/bazel/_bazel_xhu/8c8299b80b62c2e71f333df9c6122d0b/external/grpc/BUILD:1332:1: C++ compilation of rule ‘@grpc//:grpc_resolver_dns_ares’ failed (Exit 1) gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer ‘-std=c++0x’ -MD -MF … (remaining 50 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
external/grpc/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc:30:18: fatal error: ares.h: No such file or directory
compilation terminated.
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 4117.424s, Critical Path: 173.66s, Remote (0.00% of the time): [queue: 0.00%, setup: 0.00%, process: 0.00%]
INFO: 1175 processes: 1174 linux-sandbox, 1 local.
FAILED: Build did NOT complete successfully
解决:=> apt-get install libc-ares-dev
4.3 编译Pass
Target //tensorflow/tools/pip_package:build_pip_package up-to-date:
bazel-bin/tensorflow/tools/pip_package/build_pip_package
INFO: Elapsed time: 14967.427s, Critical Path: 98.21s
INFO: 7648 processes: 7648 local.
INFO: Build completed successfully, 8333 total actions
4.4 文件分布
home/.cache/bazel : 文件夹大小3.4G, 比PC小(10+G)
软连接
bazel-genfiles -> /home/xhu/.cache/bazel/_bazel_xhu/8c8299b80b62c2e71f333df9c6122d0b/execroot/org_tensorflow/bazel-out/k8-opt/genfiles
bazel-bin -> /home/xhu/.cache/bazel/_bazel_xhu/8c8299b80b62c2e71f333df9c6122d0b/execroot/org_tensorflow/bazel-out/k8-opt/bin
bazel-testlogs -> /home/xhu/.cache/bazel/_bazel_xhu/8c8299b80b62c2e71f333df9c6122d0b/execroot/org_tensorflow/bazel-out/k8-opt/testlogs
bazel-out -> /home/xhu/.cache/bazel/_bazel_xhu/8c8299b80b62c2e71f333df9c6122d0b/execroot/org_tensorflow/bazel-out
bazel-tensorflow -> /home/xhu/.cache/bazel/_bazel_xhu/8c8299b80b62c2e71f333df9c6122d0b/execroot/org_tensorflow
5.Build the Package
5.1 命令行
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
软连接:bazel-bin/tensorflow/tools/pip_package/build_pip_package -> /home/xhu/rsch/tensorflow/tensorflow/tools/pip_package/build_pip_package.sh
5.2 生成whl
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
Wed Nov 7 13:39:12 CST 2018 : === Preparing sources in dir: /tmp/tmp.HgHdbLwxOn
~/rsch/tensorflow ~/rsch/tensorflow
~/rsch/tensorflow
Wed Nov 7 13:39:16 CST 2018 : === Building wheel
warning: no files found matching ‘.pyd’ under directory '’
warning: no files found matching ‘.pd’ under directory '’
warning: no files found matching ‘.dll’ under directory '’
warning: no files found matching ‘.lib’ under directory '’
warning: no files found matching ‘.h’ under directory ‘tensorflow/include/tensorflow’
warning: no files found matching '’ under directory ‘tensorflow/include/Eigen’
warning: no files found matching ‘.h’ under directory ‘tensorflow/include/google’
warning: no files found matching '’ under directory ‘tensorflow/include/third_party’
warning: no files found matching ‘*’ under directory ‘tensorflow/include/unsupported’
Wed Nov 7 13:39:33 CST 2018 : === Output wheel file is in: /tmp/tensorflow_pkg
ls /tmp/tensorflow_pkg/ -lt
total 63884
-rw-rw-r-- 1 xhu xhu 65416475 Nov 7 13:39 tensorflow-1.12.0rc0-cp27-cp27mu-linux_x86_64.whl
=> 大小为 65.4MB
- 安装whl
6.1 pip install /tmp/tensorflow_pkg/tensorflow-1.12.0rc0-cp27-cp27mu-linux_x86_64.whl
=> 中间的数字是根据自己电脑及软件版本情况的Tag,各人可能不一样
问题1:
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: ‘/usr/local/lib/python2.7/dist-packages/astor-0.7.1.dist-info’
Consider using the --user
option or check the permissions.
=> 用sudo安装
sudo pip install /tmp/tensorflow_pkg/tensorflow-1.12.0rc0-cp27-cp27mu-linux_x86_64.whl
问题2:
Cannot uninstall ‘enum34’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
=> sudo pip install --ignore-installed enum34
Successfully installed absl-py-0.6.1 backports.weakref-1.0.post1 futures-3.2.0 gast-0.2.0 grpcio-1.16.0 keras-applications-1.0.6 keras-preprocessing-1.0.5 markdown-3.0.1 tensorboard-1.12.0 tensorflow-1.12.0rc0 tensorflow-estimator-1.10.12 termcolor-1.1.0 werkzeug-0.14.1
6.2 运行测试
$ python
import tensorflow as tf
session = tf.Session()
问题1:import tensorflow as tf
Traceback (most recent call last):
File “”, line 1, in
File “tensorflow/init.py”, line 24, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File “tensorflow/python/init.py”, line 49, in
from tensorflow.python import pywrap_tensorflow
File “tensorflow/python/pywrap_tensorflow.py”, line 25, in
from tensorflow.python.platform import self_check
ImportError: No module named platform
=> 解决: 重启terminal即可、安装后路径未更新!
==================================
修改后编译/安装:
- cd tensorflow
- python ./configure.py #(可选)
- bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
#Elapsed time: 4117.424s, 核心编译耗时1小时8分钟(实际还有前期下载,一共差不多要2个多小时) - ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
- sudo pip install /tmp/tensorflow_pkg/tensorflow-1.12.0rc0-cp27-cp27mu-linux_x86_64.whl
- Re-start Terminal