2011-10-14 43 views
4

我在我的Windows 7上安装了python 2.7。我已经安装了python 2.6自带的Libre Office 3.4。因此,即使在设置所有环境变量之后,我也无法导入uno和unohelper。Python 2.7与pyuno

我需要python 2.7,因此无法恢复到python 2.6,因为我早些时候有Python 2.6与open office 3一起工作。我最近更改为LibreOffice 3.4和Python 2.7(ActivePython 2.7)。

有没有什么办法可以使Python 2.7导入UNO和LibreOffice的3.4

感谢unohelper提前。

回答

2

.pyc文件和C扩展在2.6和2.7 Python版本之间不兼容。在与Libre Office一起使用的脚本中安装pylauncher并使用python2.6 shebang。

从答案提供给OpenOffice.org development with pyUno for Windows—which Python?问题的链接:

条款:让我们调用Python版本安装了OpenOffice的的 'OO-Python的。我们将Python的版本分开安装(例如,以 c:\ Python26为例)“System-Python”。

您需要知道六件事情才能成功将uno模块导入 您的System-Python解释器。 1)OO-Python版本号。 您的 系统Python版本号必须与您的OO-Python 版本号相同。 [重点矿] ...

+0

我没有在我的系统上安装了Python2.6,所以我试着将LibreOffice 3.4中的python.exe路径设置为“C:\ Program Files(x86)\ LibreOffice 3.4 \ program \ python.exe”。我不知道我正在尝试的是否正确,以及这种提供我的脚本所需的python可执行版本的方式是否正确。 – PyBegginer

+0

@PyBegginer:如果System和LibreOffice python的版本不同,那么你就不能在系统python中运行libreOffice中使用'pyuno'的代码。它并不妨碍你使用你发布的路径中的python运行它。 'pylauncher'允许你在不指定python版本的情况下运行你的脚本(你可以在''#!'''-line'脚本中执行一次脚本)。查看[screencast](http://www.red-dove.com/screencasts/launcher/launcher.html)。 – jfs

2

ubuntu 13.10和更高版本,你需要安装openoffice 4.1.1。

  1. 卸载的LibreOffice和OpenOffice

    sudo apt-get remove libreoffice* openoffice* 
    sudo apt-get autoremove 
    
  2. 在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 
    
  3. 在32位安装Apache OpenOffice的4.1.1 Ubuntu的

    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 
    
  4. 触摸uno.pth的python2.7

    echo /opt/openoffice4/program |sudo tee /usr/lib/python2.7/dist-packages/uno.pth 
    
0

在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