本文介绍了在我现有的python安装中使用pyuno的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PyUNO作为将Django服务器中不同文档格式(doc,wordperfect,html等)转换为PDF的方法.我很想让import uno上班.在执行import pyuno并显示消息ImportError: DLL Load Failed: The specified module could not be found时似乎失败.

I'm trying to use PyUNO as a method to convert different document formats (doc, wordperfect, html, etc) to PDF from within my Django server. I'm having a heck of a time getting import uno to work. It seems to fail when doing import pyuno, with a message of ImportError: DLL Load Failed: The specified module could not be found.

我要使它起作用的唯一方法是使用OpenOffice附带的Python 2.6,但我确实想使用我的其他2.6安装. PyUNO的文档全部用于Python 2.2,并被认为是过时的.

The only way I can get this to work is to use the Python 2.6 that came with OpenOffice, but I really want to use my other 2.6 installation. The docs for PyUNO are all for Python 2.2, and reputed to be out-of-date.

我猜测以下一些(或全部)文件需要从OpenOffice目录复制到我的站点软件包目录(或其某些子目录):

I'm guessing that some (or all) of the following files need to be copied from the OpenOffice directory to my site-packages directory (or some subdirectory thereof):

pythonloader.py
pythonloader.uno.ull
pythonloader.uno.ini
pythonscript.py
pyuno.pyd

有人能成功实现这一目标吗?

Has anyone had any success getting this to work?

这是在Windows上.

This is on Windows.

推荐答案

对于简单的转换,您无需重新发明轮子.查看unoconv: http://dag.wieers.com/home-made/unoconv/

For simply conversions, you needn't reinvent the wheel. Look at unoconv: http://dag.wieers.com/home-made/unoconv/

如果python解释器与OpenOffice捆绑在一起,或者在某些Linux系统中,打包程序已经为您完成了很多工作,那么导入uno"将自动运行.

'Import uno' will automatically work IF the python interpreter was bundled with OpenOffice, or in some Linux systems where the packagers have done a lot of work for you already.

替代1 :对于Win32系统上的其他Python安装,您需要导入三个环境变量并将一个项添加到Pythonpath中.详细的教程位于 http: //user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=36370&p=166783

Alternative 1: For other Python installs on Win32 systems, you need to import three environment variables and add one item to your Pythonpath. The detailed tutorial is at http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=36370&p=166783

必须从OO安装的Python获取并添加到其他Python安装中的三个环境变量是:(使用Python 2.6和OO 3.1.2)

The three environment variables you must get FROM your OO-installed-Python and add TO your other install of Python are:(Using Python 2.6 and OO 3.1.2)

  • os.environ ['URE_BOOTSTRAP'] ='vnd.sun.star.pathname:c:\ Program Files \ OpenOffice.org 3 \ program \ fundamental.ini'
  • os.environ ['UNO_PATH'] ='c:\ Program Files \ OpenOffice.org 3 \ program \'
  • os.environ ['PATH'].append('c:\ Program Files \ OpenOffice.org 3 \ URE \ bin; c:\ Program Files \ OpenOffice.org 3 \ Basis \ program;')

您必须添加到其他Python安装中的pythonpath项目是uno模块的位置:

The pythonpath item you must add TO your other install of Python is the location of the uno module:

  • sys.path.append('C:\ Program Files \ OpenOffice.org 3 \ Basic \ program')

现在您可以简单地导入uno".

Now you can simply 'import uno'.

Pyuno仅与类似版本的Python兼容.由于OO 3.1捆绑了Python 2.6.1,所以该pyuno仅与另一个Python 2.6兼容.尝试将uno导入到其他版本的Python中会导致运行时错误.但是替代方法2可以解决这个问题.

Pyuno is only compatible with a similar version of Python. Since OO 3.1 bundles Python 2.6.1, that pyuno is only compatible with another Python 2.6. Attempting to import uno into a different version of Python will cause a runtime error. But there's a way around that in Alternative 2.

替代2 :对于WIN32系统上安装的其他Python,您可以完全忽略Python-UNO桥,而改用Python-COM桥.您必须安装一个新模块,并且API有一些区别,但是您可以使用任何版本的Python,包括Python3.

Alternative 2: For other Python installs on WIN32 systems, you can ignore the Python-UNO bridge completely and use the Python-COM bridge instead. You must install one new module, and the API has a few differences, but you can use ANY version of Python, including Python3.

  • Install the pywin32module to get COM access: http://sourceforge.net/projects/pywin32/
  • Discussion on the API differences: http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=36608&p=168179

这篇关于在我现有的python安装中使用pyuno的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 03:23