为私有 Python 构建安装 pyuno (LibreOffice)

Jen*_*ens 5 python uno libreoffice

有几个相关的线程这个话题在这里的广告在这里,但他们似乎有点过时了。

我刚刚下载了内置 Python 3.3.0 的 LibreOffice 4。使用该 Python,我可以很好地导入和使用 UNO,并从我的 Python 脚本控制 Office。然而,我的许多其他模块都从 Python 中丢失了——而 UNO 是我的 Python 中唯一丢失的模块。

有什么办法可以为我的本地 Python 安装 pyuno?LibreOffice 源代码树包括一个 pyuno/ 源代码树,但我不确定如何将它构建/集成到另一个 Python 树中。

这里有什么经验吗?帮助?提示?做,不做,做?

编辑下面答案适用于Linux,我在扩展PYTHONPATH导入uno时没有问题。Mac 上的情况有所不同,因此请查看其他答案

编辑在修改 Python 路径时绝对要考虑这个答案

Jen*_*ens 0

Linux

dirkjot对此线程的回答在 Linux 上效果很好。

麦克(优胜美地)

这里的事情有点棘手,从 LibreOffice 4.3 开始,我仍然无法扩展PYTHONPATH到 LibreOffice 并且import uno不会在 Mac 上崩溃:

localhost ~ > PYTHONPATH=$PYTHONPATH:/Applications/LibreOffice64.app/Contents/MacOS python3.3
Python 3.3.6 (default, Nov 12 2014, 18:18:46) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import uno
Segmentation fault: 11
Run Code Online (Sandbox Code Playgroud)

但这对我有用。首先,我必须确保 Python 和我的 LibreOffice 都是针对 32b 或 64b 构建的;它们不能混合。我正在使用 64b MacPorts Python 3.3 和 64b LibreOffice for Mac(下载链接),后者附带 Python 3.3。其次,我必须确保运行正确的 Python 并PYTHONPATH正确扩展。因为我无法运行 MacPorts Python 并使用 LibreOffice 的路径扩展它,所以我必须以相反的方式执行此操作:运行 LibreOffice Python 并使用我的 MacPorts Python 路径扩展它:

localhost ~ > PYTHONPATH=$PYTHONPATH:/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages /Applications/LibreOffice64.app/Contents/MacOS/python
Python 3.3.5 (default, Dec 12 2014, 10:33:58) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import uno
>>> import lxml
>>> 
Run Code Online (Sandbox Code Playgroud)

请注意如何uno从 LibreOffice 的 Python 路径导入,并lxml驻留在 MacPort 的 Python 路径中。