随笔 - 214  文章 - 12  评论 - 40  阅读 - 38万

TensorFlow Python2.7环境下的源码编译(三)编译

一、源代码编译
这里要为仅支持 CPU 的 TensorFlow 构建一个 pip 软件包,需要调用以下命令:
$ bazel build --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --config=opt --verbose_failures //tensorflow/tools/pip_package:build_pip_package
 
提示:默认情况下,从源代码构建 TensorFlow 会消耗大量的 RAM。如果您系统中的 RAM 资源有限,则可以通过在调用 bazel 时指定 --local_resources 2048,.5,1.0 来限制 RAM 使用量。
 
编译期间因为缺少模块中断了几次,前后大概编译了几个小时,终于编译成功了!
Target //tensorflow/tools/pip_package:build_pip_package up-to-date:
  bazel-bin/tensorflow/tools/pip_package/build_pip_package
INFO: Elapsed time: 1226.516s, Critical Path: 54.42s
INFO: 904 processes: 904 local.
INFO: Build completed successfully, 1126 total actions
 
二、生成whl文件(.whl 文件的名称取决于您的平台)
bazel build 命令会构建一个名为 build_pip_package 的脚本。按如下所示运行此脚本后,一个 .whl 文件将在 /tmp/tensorflow_pkg 目录内构建:
➜  tensorflow git:(master) bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
 
2018年 8月13日 星期一 02时25分45秒 CST : === Preparing sources in dir: /var/folders/6v/q8bvbf3n209f0_59508px3pr0000gn/T/tmp.XXXXXXXXXX.nuoSUsnJ
/Volumes/DATA/AI/tensorflow /Volumes/DATA/AI/tensorflow
/Volumes/DATA/AI/tensorflow
2018年 8月13日 星期一 02时26分09秒 CST : === Building wheel
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'
2018年 8月13日 星期一 02时26分42秒 CST : === Output wheel file is in: /tmp/tensorflow_pkg
 
三、安装
首先找到具体的文件名称
➜  tensorflow git:(master) ll /tmp/tensorflow_pkg
total 98136
-rw-r--r--  1 mazhiyong  wheel    48M  8 13 02:26 tensorflow-1.10.0-cp27-cp27m-macosx_10_13_x86_64.whl
 
然后启动安装
➜  tensorflow git:(master) sudo pip2 install  /tmp/tensorflow_pkg/tensorflow-1.10.0-cp27-cp27m-macosx_10_13_x86_64.whl
 
四、验证
1、首先切换工作目录到tensorflow目录外,切记!
➜  tensorflow git:(master) cd ~
 
2、调用 Python2:
$ python2
 
3、验证
在 Python 交互式 shell 中输入以下几行简短的程序代码:
# Python
importtensorflow astf
hello =tf.constant('Hello, TensorFlow!')
sess =tf.Session()
print(sess.run(hello))
如果系统输出以下内容,就说明您可以开始编写 TensorFlow 程序了:
Hello, TensorFlow!
 
从二进制安装方式到源码编译方式前后折腾了两周,终于看到结果啦!
 
posted on   麦克煎蛋  阅读(1155)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示