OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

PyUNO and OOo-v1.1RC

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
bryancole
OOo Advocate
OOo Advocate


Joined: 13 Jun 2003
Posts: 305

PostPosted: Wed Jul 23, 2003 9:48 am    Post subject: PyUNO and OOo-v1.1RC Reply with quote

I'm trying to test out PyUNO with OOo-v1.1rc. As I understand it, it should work "out of the box" (provided you select PyUNO installation during OO install, which I did). I have the python runtime etc. but the HelloWorld tutorials don't work for me. Do I need to download anything else to use PyUNO, other than the linux OOo1.1rc binaries?
Back to top
View user's profile Send private message
dfrench
Moderator
Moderator


Joined: 03 Mar 2003
Posts: 1605
Location: Wellington, New Zealand

PostPosted: Sat Jul 26, 2003 1:14 pm    Post subject: Reply with quote

Did you get anywhere with this, Bryan? I followed the instructions and got

Quote:

C:\Program Files\OpenOffice.org1.1\program>.\python helloworld.py
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

I did try pythonwin instead and got

Quote:
Traceback (most recent call last):
File "C:\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Program Files\OpenOffice.org1.1\program\helloworld.py", line 4, in ?
localContext = uno.getComponentContext()
AttributeError: 'module' object has no attribute 'getComponentContext'
Back to top
View user's profile Send private message
dfrench
Moderator
Moderator


Joined: 03 Mar 2003
Posts: 1605
Location: Wellington, New Zealand

PostPosted: Sat Jul 26, 2003 9:09 pm    Post subject: Reply with quote

I am now happily scripting OOo with pythonwin2.2.3 (build 152). I don't know what I did differently but after the installation, the steps below work
1. Start pythonwin
2. Close all OOo windows, exit the quickstarter
3. In CMD
cd \Program Files\OpenOffice.org1.1\program
soffice "-accept=socket,host=localhost,port=2002;urp;"
4.Load hello_world.py into pythonwin and run
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Aug 16, 2003 12:51 pm    Post subject: Reply with quote

I can't get this to work.

WinXP. OOo 1.1 RC1. I have installed Python 2.3, and also Python 2.2.3. It is the 2.2.3 that I am trying to get to work, as dfrench shows.

My python says...

Python 2.2.3 (#42, May 30 2003, 18:12:0Cool [MSC 32 bit (Intel)] on win32

I do this....

Code:
import sys
sys.path = sys.path + ["....path to OOo...\\program"]
sys.path = sys.path + [".....path to OOo...\\program\python-core-2.2.2\\lib"]


No problem. Now, I can find the uno.py within OOo.

So I say...

Code:
import uno


I get....

Traceback (most recent call last):
File "<pyshell#4>", line 1, in ?
import uno
File "C:\Program Files\OpenOffice.org1.1\program\uno.py", line 67, in ?
_g_ctx = pyuno.getComponentContext( )
SystemError: pyuno runtime is not initialized, (the pyuno.bootstrap needs to be called before using any uno classes)

So obviously, it is finding uno.py. This seems very similar to what dfrench did. But it does not work.

If I could get past the "import uno", then I would try running HelloWorld.py. (My OOo always listens on port 8100 instead of 2100, because my Java programs are already written that way.)
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
dfrench
Moderator
Moderator


Joined: 03 Mar 2003
Posts: 1605
Location: Wellington, New Zealand

PostPosted: Sat Aug 16, 2003 2:18 pm    Post subject: Reply with quote

Quote:
SystemError: pyuno runtime is not initialized, (the pyuno.bootstrap needs to be called before using any uno classes)
This is probably a pretty general failure message but I get that if I have not done the command line start up with port 2002.[/code]
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Mon Aug 18, 2003 9:46 am    Post subject: Reply with quote

Quote:
This is probably a pretty general failure message but I get that if I have not done the command line start up with port 2002.


Thanks for the info. But it doesn't seem to help.

I wouldn't expect the fact OOo is listening to actually matter until after you get past the

Code:
import uno


statement, and start trying to create a connection. My problem is that I can't simply "import uno".

Again, I'm running Python 2.2.3. I'm running a separately installed Python that is NOT the python that is included within OOo. Just in case that is important.

What I'm wanting here is an interactive Python with IDLE that I can interactively create and manipulate uno objects with. I can do this in Visual FoxPro, and I like it. Much better than with Java, where you have to compile a program, try it, edit, compile, test, etc. Not to mention the Java clumsiness of having to constantly query for different interfaces.

Maybe I should be trying to run the python that is included in OOo, and somehow get IDLE working from there? But I do not know how to do this?
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Mon Aug 18, 2003 10:06 am    Post subject: Reply with quote

If I run the python.bat file in OpenOffice\program, I get python in a command window. (Not what I want.)

Even if I "import sys", and then add to the sys.path, a couple of paths to where my IDLE from my installed python is, I cannot run IDLE. Idle does not run, because it imports PyShell. And PyShell imports "os".

If I run the command line python.bat within OOo, I also am unable to even execute a simple statement like "import os". I don't understand this. (I'm not super experienced with python yet, of course.) The OOo\program\python-core-2.2.2\lib does have a "os.py" file, so why can't I "import os" ?
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed Aug 20, 2003 12:19 pm    Post subject: Reply with quote

Finally, some success!

Here is what I wanted to achieve: Ability to use GUI python (IDLE) to work interactivelly in GUI, and also be able to interactivelly work with uno connected to OOo. I do this in Visual FoxPro and it is great. I can enter a single command at a time to create and manipulate documents. I want this ability in Python.


My OOo is installed at C:\Program Files\OpenOffice.org1.1

My Python 2.2 is installed at C:\Python22


I copied the tcl folder from my Python over to the OOo\program\python-core-2.2.2\ folder.

The python.bat file in the OOo\program folder is just wrong. It says...

Code:

@echo off
set PATH=%PATH%;"C:\Program Files\OpenOffice.org1.1\program"
set PYTHONPATH="C:\Program Files\OpenOffice.org1.1\program;C:\Program Files\OpenOffice.org1.1\program\python-core-2.2.2\lib"
set PYTHONHOME="C:\Program Files\OpenOffice.org1.1\program\python-core-2.2.2"
"C:\Program Files\OpenOffice.org1.1\program\python-core-2.2.2\bin\python.exe" %1 %2 %3 %4 %5 %6 %7 %8 %9


Note the double quotes around the PYTHONPATH variable.

I don't remember now if the file came this way, or if I had added those quotes at some point. In any case, remove them.

These double quotes was why I couldn't even execute a simple statement, such as "import os".


In order to use the GUI IDLE development in python, I wrote a new python.bat file like this....

Code:

@echo off
set PATH="C:\Program Files\OpenOffice.org1.1\program;%PATH%"

set PYTHONPATH=

set PYTHONPATH=%PYTHONPATH%;C:\Python22\
set PYTHONPATH=%PYTHONPATH%;C:\Python22\DLLs
set PYTHONPATH=%PYTHONPATH%;C:\Python22\lib
set PYTHONPATH=%PYTHONPATH%;C:\Python22\lib\lib-tk
set PYTHONPATH=%PYTHONPATH%;C:\Python22\lib\site-packages
set PYTHONPATH=%PYTHONPATH%;C:\python22\Tools\idle

set PYTHONPATH=%PYTHONPATH%;C:\Program Files\OpenOffice.org1.1\program
set PYTHONPATH=%PYTHONPATH%;C:\Program Files\OpenOffice.org1.1\program\python-core-2.2.2\lib

set PYTHONHOME=C:\Program Files\OpenOffice.org1.1\program\python-core-2.2.2

"C:\Program Files\OpenOffice.org1.1\program\python-core-2.2.2\bin\python.exe" C:\python22\Tools\idle\idle.py %1 %2 %3 %4 %5 %6 %7 %8 %9


Note that on PATH, I put the OOo/program folder at the front of the path, not the end.

I made PYTHONPATH point to folders in my Python22 installation, so that IDLE would work. I also make it point to the two folders it needs in the OOo\program folder.

Finally, when I call the python.exe, I pass it an argument to start IDLE running.

(Don't forget to copy the tcl folder from your Python installation over to your OOo\program\python-core-2.2.2 folder.)

Boy do I wish that the python included in OOo had just included IDLE.

But now I can run Python, with IDLE, and do the "import uno".
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group