Python 2.7与pyuno
我在我的Windows 7上安装了Python 2.7。同时,我也安装了Libre Office 3.4,这里面自带了Python 2.6。因此,即使我设置了所有的环境变量,我还是无法导入uno和unohelper。
我需要使用Python 2.7,所以不能退回到Python 2.6,因为我之前用Python 2.6和Open Office 3是可以正常工作的。最近我换成了LibreOffice 3.4和Python 2.7(ActivePython 2.7)。
有没有办法让我用Python 2.7导入LibreOffice 3.4中的uno和unohelper呢?
提前谢谢你。
3 个回答
在Ubuntu 14.04系统中
打开终端,然后输入以下命令...
sudo apt-get install libreoffice python-genshi python-cairo python-lxml python-setuptools
sudo apt-get install libreoffice-script-provider-python
easy_install uno
在Ubuntu 13.10及以后的版本中,你需要安装OpenOffice 4.1.1。
先卸载LibreOffice和OpenOffice。
sudo apt-get remove libreoffice* openoffice* sudo apt-get autoremove
在64位的Ubuntu上安装Apache OpenOffice 4.1.1。
wget sourceforge.net/projects/openofficeorg.mirror/files/4.1.1/binaries/en-GB/Apache_OpenOffice_4.1.1_Linux_x86-64_install-deb_en-GB.tar.gz tar -xzvf Apache_OpenOffice_4.1.1_Linux_x86-64_install-deb_en-GB.tar.gz cd en-GB/DEBS sudo dpkg -i *.deb cd desktop-integration sudo dpkg -i *.deb
在32位的Ubuntu上安装Apache OpenOffice 4.1.1。
wget sourceforge.net/projects/openofficeorg.mirror/files/4.1.1/binaries/en-GB/Apache_OpenOffice_4.1.1_Linux_x86_install-deb_en-GB.tar.gz tar -xzvf Apache_OpenOffice_4.1.1_Linux_x86_install-deb_en-GB.tar.gz cd en-GB/DEBS sudo dpkg -i *.deb cd desktop-integration sudo dpkg -i *.deb
为Python 2.7创建一个名为uno.pth的文件。
echo /opt/openoffice4/program |sudo tee /usr/lib/python2.7/dist-packages/uno.pth
.pyc
文件和 C 扩展在 Python 2.6 和 2.7 版本之间是不兼容的。如果你要在 Libre Office 中使用脚本,建议安装 pylauncher,并在脚本中使用 python2.6 的 shebang。
在回答关于 Windows 上使用 pyUno 开发 OpenOffice.org——用哪个 Python? 的问题时提供的链接中提到:
术语:我们把与 OpenOffice 一起安装的 Python 版本称为 'OO-Python'。把单独安装的 Python 版本(比如安装在 c:\Python26)称为 'System-Python'。
要成功将 uno 模块导入到你的 System-Python 解释器中,你需要知道六件事。第一件:OO-Python 的版本号。你的 System-Python 版本号必须和 OO-Python 版本号相同。 [强调是我加的]