Tensorflow从源代码(Win7)安装:bazel,python->;没有名为';编码'; 目标
在c/c++中使用Python训练(keras)模型。 有关c-变通方法,请参见“变通方法”一节 从源代码处编译Tensorflow(版本1.0或1.2.1) 按照 < P>(TysFooad已经通过Python 3中的PIP安装,但我需要从C++使用它,所以从源安装似乎是强制性的) 系统Tensorflow从源代码(Win7)安装:bazel,python->;没有名为';编码'; 目标,python,machine-learning,tensorflow,windows-7-x64,bazel,Python,Machine Learning,Tensorflow,Windows 7 X64,Bazel,在c/c++中使用Python训练(keras)模型。 有关c-变通方法,请参见“变通方法”一节 从源代码处编译Tensorflow(版本1.0或1.2.1) 按照 < P>(TysFooad已经通过Python 3中的PIP安装,但我需要从C++使用它,所以从源安装似乎是强制性的) 系统 win7(64) bazel 0.5.2 python(env)3.5.2(64) pip(环境)9.0.1 msys64/msys2_shell.cmd(GNU bash,4.4.12(64个msys)
- win7(64)
- bazel 0.5.2
- python(env)3.5.2(64)
- pip(环境)9.0.1
- msys64/msys2_shell.cmd(GNU bash,4.4.12(64个msys))
- gcc 6.3.0
- java SE“1.8.0_131”
- CUDA 8.0.60(未使用)
bazel build --verbose_failures --config=opt //tensorflow/tools/pip_package:build_pip_package
我得到这个错误:
ERROR: D:/user/sourcen/external/tensorflow-master-201707051514/
tensorflow-master-rev-1-2-1/tensorflow/core/BUILD:1415:1:
Executing genrule //tensorflow/core:version_info_gen failed:
bash.exe failed: error executing command
cd C:/users/user/appdata/local/temp/_bazel_user/chogfwdz/execroot/org_tensorflow
C:/tools/msys64/usr/bin/bash.exe
-c source external/bazel_tools/tools/genrule/genrule-setup.sh;
tensorflow/tools/git/gen_git_source.py
--generate tensorflow/tools/git/gen/spec.json
tensorflow/tools/git/gen/head
tensorflow/tools/git/gen/branch_ref
"bazel-out/host/genfiles/tensorflow/core/util/version_info.cc":
com.google.devtools.build.lib.shell.
BadExitStatusException: Process exited with status 3.
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
对不起,我完全迷路了,这条消息告诉我什么。
这里有一些上面提到的文件片段,也许有人有胶水,给了我启示
//tensorflow/核心/构建:1415:1 tf_版本_信息_genrule()
bazel/../genrule-setup.sh
set -e
set -u
set -o pipefail
//tensorflow/tools/git/gen\u git\u source.py
"""... creates symlinks from the internal git repository directory so
that the build system can see changes in the version state. ..."""
def parse_branch_ref(filename)...
def configure(src_base_path, debug=False)...
def get_git_version(git_base_path)...
def write_version_info(filename, git_version)...
def generate(arglist)...
def raw_generate(output_file)...
我想,使用了错误的python版本(不是我激活的virtualenv)——安装了其他几个python版本(2.7-32、2.7-64、3.5-32、3.5-64)(否则需要) 问题 如果bazel使用的是正确的python(virtualenv),我可以做什么来检查 如果bazel使用的是错误的,我该如何更改 如果bazel使用的是正确的版本,我如何才能获得更多关于出错原因的详细信息(并修复它) 元问题 需要什么进一步的信息(环境变量) 我能做些什么来改进问题,使人们能够给出建议? (请给出评论,缺少什么、错误、不清楚、太多) 下一步 我搜索了“致命Python错误:Py_初始化:无法加载文件系统编解码器” ImportError:没有名为“encodings”的模块
- 尝试使用本地管理员帐户->被公司防火墙阻止,执行以下步骤
- 尝试设置PYTHONPATH和PYTHONHOME,没有效果 导出PYTHONHOME=/D/bin/Python64-3-Anaconda/envs/Python64-35 导出PYTHONPATH=/D/bin/Python64-3-Anaconda/envs/Python64-35: /D/bin/Python64-3-Anaconda/envs/Python64-35/lib/site包: /d/bin/Python64-3-Anaconda/envs/Python64-35/libs
- 尝试设置另一个virtualenv(作为管理员)
- 尝试通过cmake安装tensorflow
d:/bin/Python64-3-Anaconda/envs/python64-35/python.exe,
作为我使用的库路径:
D:/bin/Python64-3-Anaconda/envs/python64-35/lib/site-packages.
TF1.0尝试
修补生成(TF1.0)
步骤0:设置环境,激活python环境,cd
启动msys2外壳:
$ c:/tools/msys64/msys2_shell.cmd
设置环境变量
user@CRPC0815 MSYS ~
$ source d:/user/00-Projekte/VrVis/env-cuda-python64-3--1.sh
激活虚拟环境
$ cd /d/bin/Python64-3-Anaconda/
$ source activate python64-35
转到来源
$ cd /d/user/Sourcen/external/tensorflow-rev1-0
(python64-35)
user@CRPC0815 MSYS /d/user/Sourcen/external/tensorflow-rev1-0
$
步骤1:bazel清洁
步骤2:/配置
TF 1.2.1构建尝试
步骤0:设置环境,激活python环境,cd
(与TF 1.0中的相同)
步骤1:bazel清洁
步骤2:/配置
步骤3:bazel构建和错误
变通
同时,我找到了一种在不需要bazel/cmake/sources的情况下部署Tensorflow(Keras)模型(win7/win10)的解决方法
- 使用中的C-API C_API.h
- 通过vs2015命令提示符从dll创建库: dumpbin/exports xxx.dll>xxx.def pywrap_tensorflow_internal.lib
- 从Python pywrap_tensorflow_internal.lib中提取gpu库
- 将pyd lib\u pywrap\u tensorflow\u internal.pyd复制到dll路径
- 可能使用gpu选项(python->c):
- python代码 gpu_选项=tensorflow.gpu选项(允许_增长=真) config=tensorflow.ConfigProto(gpu\U选项=gpu\U选项) serialized=config.SerializeToString() [int(i)表示序列化中的i]
- gpu选项的c代码: TF_SessionOptions*sess_opts=TF_NewSessionOptions() //tensorflow.gpu选项(允许增长=真) uint8_t configProtoGPU[]={50,2,32,1} size\u t configProtoGPUlen=sizeof(configProtoGPU)/sizeof(uint8\u t) TF_SetConfig(sess_选项、configProtoGPU、configProtoGPUlen、状态)
$ cd /d/bin/Python64-3-Anaconda/
$ source activate python64-35
$ cd /d/user/Sourcen/external/tensorflow-rev1-0
(python64-35)
user@CRPC0815 MSYS /d/user/Sourcen/external/tensorflow-rev1-0
$
(python64-35)
user@CRPC0815 MSYS /d/user/Sourcen/external/tensorflow-rev1-0
$ bazel clean
WARNING: ignoring http_proxy in environment.
....................
INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes.
(python64-35)
user@CRPC0815 MSYS /d/user/Sourcen/external/tensorflow-rev1-0
$ ./configure
Please specify the location of python.
[Default is /D/bin/Python64-3-Anaconda/envs/python64-35/python]:
Please specify optimization flags to use during compilation [Default is -march=native]:
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N]
No XLA support will be enabled for TensorFlow
Found possible Python library paths:
D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages
D:\bin\Python64-3-Anaconda\envs\python64-35
Please input the desired Python library path to use.
Default is [D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages]
Using python library path: D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages
Junction created for util\python\python_include <<===>> D:\bin\Python64-3-Anaconda\envs\python64-35\include
Junction created for util\python\python_lib <<===>> D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages
Junction created for third_party\py\numpy\numpy_include <<===>> D:\bin\Python64-3-Anaconda\envs\
python64-35\lib\site-packages\numpy\core\include
Do you wish to build TensorFlow with CUDA support? [y/N]
No CUDA support will be enabled for TensorFlow
Configuration finished
WARNING: ignoring http_proxy in environment.
INFO: All external dependencies fetched successfully.
$ bazel build --verbose_failures --config=opt //tensorflow/tools/pip_package:build_pip_package
WARNING: ignoring http_proxy in environment.
INFO: Found 1 target...
ERROR: D:/user/sourcen/external/tensorflow-rev1-0/tensorflow/core/BUILD:1227:1:
Executing genrule //tensorflow/core:version_info_gen failed:
bash.exe failed:
error executing command
cd C:/users/user/appdata/local/temp/_bazel_user/hnxszhzu/execroot/org_tensorflow
SET PATH=C:\tools\msys64\usr\bin;C:\tools\msys64\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35;
D:\bin\Python64-3-Anaconda\envs\python64-35\Library\mingw-w64\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35\Library\usr\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35\Library\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35\Scripts;
C:\tools\msys64\usr\bin;
D:\user\bin\BLAS;
D:\bin\TDM-GCC-64\bin;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\bp2qlotc.p22\NativeBinaries\x86;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\;
C:\Program Files (x86)\MSBuild\14.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\libnvvp;
C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\lib;
C:\Program Files\TortoiseGit\bin;
C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;
C:\ProgramData\Oracle\Java\javapath;
C:\Qt\Qt5.7.0\5.7\msvc2015;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\WINDOWS\system32;
D:\user\bin\MinGW\msys\1.0\bin;
D:\user\bin\MinGW\msys\1.0\sbin;
D:\user\bin\MinGW\msys\1.0\sbin\awk;
D:\bin\CMake\bin;
D:\bin\Git\bin;
[...]
D:\bin\Python64-3-Anaconda\envs\python64-35\DLLs;
D:\bin\Python64-3-Anaconda\envs\python64-35\Lib;
D:\bin\Python64-3-Anaconda\envs\python64-35\libs;
D:\bin\Slik-Subversion-1-9-2\bin;
D:\bin\SubversionColabnet\bin;
D:\bin\TDM-GCC-64\bin;
C:\tools\msys64\usr\local\bin;
C:\tools\msys64\usr\bin;
C:\tools\msys64\usr\bin;
C:\tools\msys64\opt\bin;
C:\Windows\System32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\tools\msys64\usr\bin\site_perl;
C:\tools\msys64\usr\bin\vendor_perl;
C:\tools\msys64\usr\bin\core_perl
C:/tools/msys64/usr/bin/bash.exe -c source external/bazel_tools/tools/genrule/genrule-setup.sh;
tensorflow/tools/git/gen_git_source.py
--generate tensorflow/tools/git/gen/spec.json
tensorflow/tools/git/gen/head
tensorflow/tools/git/gen/branch_ref
"bazel-out/host/genfiles/tensorflow/core/util/version_info.cc":
com.google.devtools.build.lib.
shell.BadExitStatusException: Process exited with status 3.
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
Current thread 0x0000628c (most recent call first):
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 5,500s, Critical Path: 0,41s
$ source d:/user/00-Projekte/VrVis/env-cuda-python64-3--1.sh
$ cd /d/bin/Python64-3-Anaconda/
$ source activate python64-35
$ cd /d/user/Sourcen/external/tensorflow-master-201707051514/tensorflow-master-rev-1-2-1/
$ bazel clean
WARNING: ignoring http_proxy in environment.
INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes
$ ./configure
WARNING: ignoring http_proxy in environment.
You have bazel 0.5.2- installed.
Please specify the location of python.
[Default is /D/bin/Python64-3-Anaconda/envs/python64-35/python]:
Found possible Python library paths:
D:\bin\Python64-3-Anaconda\envs\python64-35
D:\bin\Python64-3-Anaconda\envs\python64-35\lib\site-packages
Please input the desired Python library path to use.
Default is [D:\bin\Python64-3-Anaconda\envs\python64-35]
D:/bin/Python64-3-Anaconda/envs/python64-35/lib/site-packages
Do you wish to build TensorFlow with MKL support? [y/N]
No MKL 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]:
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N]
No XLA support will be enabled for TensorFlow
Do you wish to build TensorFlow with VERBS support? [y/N]
No VERBS support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N]
No CUDA support will be enabled for TensorFlow
Do you wish to build TensorFlow with MPI support? [y/N]
MPI support will not be enabled for TensorFlow
Configuration finished
(python64-35)
user@CRPC0815 MSYS /d/user/Sourcen/external/tensorflow-master-201707051514/tensorflow-master-rev-1-2-1
$ bazel build --verbose_failures --config=opt //tensorflow/tools/pip_package:build_pip_package
WARNING: ignoring http_proxy in environment.
INFO: Found 1 target...
ERROR: D:/user/sourcen/external/tensorflow-master-201707051514/tensorflow-master-rev-1-2-1/tensorflow/core/BUILD:1415:1:
Executing genrule //tensorflow/core:version_info_gen failed:
bash.exe failed:
error executing command
cd C:/users/user/appdata/local/temp/_bazel_user/chogfwdz/execroot/org_tensorflow
SET PATH=C:\tools\msys64\usr\bin;
C:\tools\msys64\bin;
C:\tools\msys64\usr\bin;
D:\user\bin\BLAS;
D:\bin\TDM-GCC-64\bin;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\bp2qlotc.p22\NativeBinaries\x86;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\;
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\;
C:\Program Files (x86)\MSBuild\14.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\libnvvp;
C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\lib;
C:\Program Files\TortoiseGit\bin;
C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;
C:\ProgramData\Oracle\Java\javapath;
C:\Qt\Qt5.7.0\5.7\msvc2015;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\WINDOWS\system32;
D:\BaslerPylon5\Runtime\Win32\;
D:\BaslerPylon5\Runtime\x64\;
D:\user\bin\MinGW\msys\1.0\bin;
D:\user\bin\MinGW\msys\1.0\sbin;
D:\user\bin\MinGW\msys\1.0\sbin\awk;
D:\bin\CMake\bin;
D:\bin\Git\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35;
D:\bin\Python64-3-Anaconda\envs\python64-35\Library\bin;
D:\bin\Python64-3-Anaconda\envs\python64-35\Scripts;
D:\bin\Python64-3-Anaconda\envs\python64-35\DLLs;
D:\bin\Python64-3-Anaconda\envs\python64-35\Lib;
D:\bin\Python64-3-Anaconda\envs\python64-35\libs;
D:\bin\Slik-Subversion-1-9-2\bin;
D:\bin\SubversionColabnet\bin;
D:\bin\TDM-GCC-64\bin;
D:\bin\gnuplot\bin;
D:\user\bin;
.
C:/tools/msys64/usr/bin/bash.exe -c source external/bazel_tools/tools/genrule/genrule-setup.sh;
tensorflow/tools/git/gen_git_source.py
--generate tensorflow/tools/git/gen/spec.json
tensorflow/tools/git/gen/head tensorflow/tools/git/gen/branch_ref
"bazel-out/host/genfiles/tensorflow/core/util/version_info.cc":
com.google.devtools.build.lib.shell.
BadExitStatusException: Process exited with status 3.
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
Current thread 0x000036e8 (most recent call first):
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 5,413s, Critical Path: 0,52s