如何在 MacOSX 上用 pyinstaller 打包 tensorflow?
How to package tensorflow with pyinstaller on MacOSX?
我正在分发一个包含 tensorflow 的 python 程序。在 OSX、python 2.7 上,我在加载库和 运行ning tensorflow 时没有出现错误。使用 pyinstaller 创建可执行文件时失败并出现 PBR 错误。
我们可以将此问题简化为一个简单的(希望可重现的)错误。
这是我们的程序。让我们加载 tensorflow 并让它打印出一些路径信息。
tf_check.py
import tensorflow
print(tensorflow.__file__)
运行 使用 pyinstaller。
Bens-MacBook-Pro:tests ben$ pyinstaller tf_check.py
66 INFO: PyInstaller: 3.3
66 INFO: Python: 2.7.10
78 INFO: Platform: Darwin-16.7.0-x86_64-i386-64bit
79 INFO: wrote /Users/ben/Documents/DeepMeerkat/tests/tf_check.spec
87 INFO: UPX is not available.
构建没有问题。尝试 运行 tf_check under dist/tf_check/
产量
Last login: Thu Sep 28 12:54:34 on ttys000
Bens-MacBook-Pro:~ ben$ /Users/ben/Documents/DeepMeerkat/tests/dist/tf_check/tf_check ; exit;
Traceback (most recent call last):
File "tf_check.py", line 1, in <module>
File "/Library/Python/2.7/site-packages/PyInstaller-3.3-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "tensorflow/__init__.py", line 24, in <module>
File "/Library/Python/2.7/site-packages/PyInstaller-3.3-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "tensorflow/python/__init__.py", line 107, in <module>
File "/Library/Python/2.7/site-packages/PyInstaller-3.3-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "tensorflow/python/platform/test.py", line 60, in <module>
File "/Library/Python/2.7/site-packages/PyInstaller-3.3-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "mock/__init__.py", line 2, in <module>
File "/Library/Python/2.7/site-packages/PyInstaller-3.3-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "mock/mock.py", line 71, in <module>
File "pbr/version.py", line 461, in semantic_version
File "pbr/version.py", line 448, in _get_version_from_pkg_resources
File "pbr/packaging.py", line 755, in get_version
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name mock was given, but was not able to be found.
[1916] Failed to execute script tf_check
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Deleting expired sessions...9 completed.
[Process completed]
一些系统信息
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> tensorflow.__version__
'1.3.0'
相同的代码在 Windows 上运行没有问题。同样,仅当使用 pyinstaller 分发时。
任何人都可以在 OSX 上展示打包 tensorflow 的示例吗?
编辑 #1
正在关注
我尝试在干净的虚拟环境中安装,只需 pip install
tensorflow 和 pip 安装 pyinstaller,没有改善。
我尝试在构建 pyinstaller 之前导出 PBR 版本
tf_check.py,无改善。
(env) Bens-MacBook-Pro:tests ben$ echo $PBR_VERSION
3.1.1
(env) Bens-MacBook-Pro:tests ben$ open dist/tf_check/tf_check
在导入之前放置在 tensorflow 脚本的顶部。
import os
#export pbr version for tensorflow user
os.environ["PBR_VERSION"]='3.1.1'
或者 pbr -v 给你的任何版本
我正在分发一个包含 tensorflow 的 python 程序。在 OSX、python 2.7 上,我在加载库和 运行ning tensorflow 时没有出现错误。使用 pyinstaller 创建可执行文件时失败并出现 PBR 错误。
我们可以将此问题简化为一个简单的(希望可重现的)错误。
这是我们的程序。让我们加载 tensorflow 并让它打印出一些路径信息。
tf_check.py
import tensorflow
print(tensorflow.__file__)
运行 使用 pyinstaller。
Bens-MacBook-Pro:tests ben$ pyinstaller tf_check.py
66 INFO: PyInstaller: 3.3
66 INFO: Python: 2.7.10
78 INFO: Platform: Darwin-16.7.0-x86_64-i386-64bit
79 INFO: wrote /Users/ben/Documents/DeepMeerkat/tests/tf_check.spec
87 INFO: UPX is not available.
构建没有问题。尝试 运行 tf_check under dist/tf_check/
产量
Last login: Thu Sep 28 12:54:34 on ttys000
Bens-MacBook-Pro:~ ben$ /Users/ben/Documents/DeepMeerkat/tests/dist/tf_check/tf_check ; exit;
Traceback (most recent call last):
File "tf_check.py", line 1, in <module>
File "/Library/Python/2.7/site-packages/PyInstaller-3.3-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "tensorflow/__init__.py", line 24, in <module>
File "/Library/Python/2.7/site-packages/PyInstaller-3.3-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "tensorflow/python/__init__.py", line 107, in <module>
File "/Library/Python/2.7/site-packages/PyInstaller-3.3-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "tensorflow/python/platform/test.py", line 60, in <module>
File "/Library/Python/2.7/site-packages/PyInstaller-3.3-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "mock/__init__.py", line 2, in <module>
File "/Library/Python/2.7/site-packages/PyInstaller-3.3-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 396, in load_module
exec(bytecode, module.__dict__)
File "mock/mock.py", line 71, in <module>
File "pbr/version.py", line 461, in semantic_version
File "pbr/version.py", line 448, in _get_version_from_pkg_resources
File "pbr/packaging.py", line 755, in get_version
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name mock was given, but was not able to be found.
[1916] Failed to execute script tf_check
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Deleting expired sessions...9 completed.
[Process completed]
一些系统信息
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> tensorflow.__version__
'1.3.0'
相同的代码在 Windows 上运行没有问题。同样,仅当使用 pyinstaller 分发时。
任何人都可以在 OSX 上展示打包 tensorflow 的示例吗?
编辑 #1
正在关注
我尝试在干净的虚拟环境中安装,只需 pip install tensorflow 和 pip 安装 pyinstaller,没有改善。
我尝试在构建 pyinstaller 之前导出 PBR 版本 tf_check.py,无改善。
(env) Bens-MacBook-Pro:tests ben$ echo $PBR_VERSION
3.1.1
(env) Bens-MacBook-Pro:tests ben$ open dist/tf_check/tf_check
在导入之前放置在 tensorflow 脚本的顶部。
import os
#export pbr version for tensorflow user
os.environ["PBR_VERSION"]='3.1.1'
或者 pbr -v 给你的任何版本