Old 11-25-2009, 12:21 PM   #1
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default error python scripting

when trying to run the simple python script with this single line in a .py file
RPR_Main_OnCommand(40746, 0)

i get a bizarre syntax error message as shown in the attached screen dump.

It remains impossible to run a python script on my OSX snow leopard using the latest version of reaper v3.1415pre2/OSX

howto proceed ?

F
Attached Images
File Type: png Screen shot 2009-11-25 at 20.14.12.png (45.7 KB, 283 views)
klankschap is offline   Reply With Quote
Old 11-25-2009, 01:06 PM   #2
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

I don't know much and only just these days edited an existing Python script to run in Reaper. So I shoot my one single arrow that I stumbled over:
Python scripts (maybe only for ReaScript, dunno) need to have an empty line at the end, so the last thing you write must be the "enter" key.

Really do hope this helps I never thought I could one day try and answer a thing in the developer forum. It would feel awesome if on top of that it was the right answer .
gofer is offline   Reply With Quote
Old 11-25-2009, 01:19 PM   #3
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default

Quote:
Originally Posted by gofer View Post
Python scripts (maybe only for ReaScript, dunno) need to have an empty line at the end, so the last thing you write must be the "enter" key.
No this is not the case.
The error message is not covering the issue.
Yet it is impossible to run any python reascript.
Even the suggested test.

Maybe the author can fill in some hints...

F
klankschap is offline   Reply With Quote
Old 11-25-2009, 01:44 PM   #4
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,815
Default

What version of Python do you have installed?
schwa is offline   Reply With Quote
Old 11-25-2009, 02:13 PM   #5
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default

Quote:
Originally Posted by schwa View Post
What version of Python do you have installed?
Both the standard 2.6.3 as well as 3.1.1
But i see no hint as how to tell reaper which one to use.

i can start both in the Terminal,
either 2.6.3
>python
or 3.1.1
>python3

It would make sense to include python in the reaper application (just like blender does)

F
klankschap is offline   Reply With Quote
Old 11-25-2009, 02:43 PM   #6
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,815
Default

Quote:
Originally Posted by klankschap View Post
It would make sense to include python in the reaper application (just like blender does)
Not really, because it would make the Reaper installer 1.5x bigger for a feature that most people won't use.

Reaper will look for libpython.dylib, which is usually a symbolic link to the latest version of Python, but if typing "python" from the command line gives you 2.6.3 then your libpython.dylib probably points to that version, and that's why ReaScript is failing.

If you type "which python3" on the command line what does it say? If there is a typical way for OSX users to have both Python v2 and v3 installed, we can maybe have ReaScript look for v3 first.
schwa is offline   Reply With Quote
Old 11-25-2009, 02:52 PM   #7
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default

Quote:
Originally Posted by schwa View Post
If you type "which python3" on the command line what does it say? If there is a typical way for OSX users to have both Python v2 and v3 installed, we can maybe have ReaScript look for v3 first.
While the transition is still in progress, the 3.1 version is installed separate from the 2.6 version.
So if reaper would have a field in the preferences to point to the python version to be used, that might solve the problem.

$ which python3
/usr/local/bin/python3

$ which python
/Library/Frameworks/Python.framework/Versions/2.6/bin/python
klankschap is offline   Reply With Quote
Old 11-25-2009, 03:05 PM   #8
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,815
Default

If you can locate the dylib that the python3 executable invokes (probably called something like libpython3.1.dylib), you could try creating a symbolic link to it from the Reaper app directory using

Code:
ln -s /wherever/you/find/libpython3.1.dylib /wherever/reaper/is
Not sure if that would work or not, depends on the path search order.
schwa is offline   Reply With Quote
Old 11-25-2009, 03:47 PM   #9
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default

Quote:
Originally Posted by schwa View Post
If you can locate the dylib that the python3 executable invokes (probably called something like libpython3.1.dylib), you could try creating a symbolic link to it from the Reaper app directory using

Code:
ln -s /wherever/you/find/libpython3.1.dylib /wherever/reaper/is
No too sure if I can follow. The /usr/local/bin/python3 is a symbolic link itself.
Would it be enough to copy that in the /Applications/Reaper folder where Reaper.app is ?

Or could it be placed in the preferences somewhere ?
Like a path to an alien editor or something ?

F
klankschap is offline   Reply With Quote
Old 11-26-2009, 01:26 AM   #10
MikeLacey
Human being with feelings
 
Join Date: Dec 2006
Location: UK
Posts: 789
Default

"ln -s"

That's UNIX...
__________________
Mike Lacey, Leicestershire, UK
MikeLacey is offline   Reply With Quote
Old 11-26-2009, 01:42 AM   #11
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default

Quote:
Originally Posted by MikeLacey View Post
"ln -s"

That's UNIX...
that i know.
it is more what to link where, and if a copy of an existing link will do too.

F
klankschap is offline   Reply With Quote
Old 11-26-2009, 06:41 AM   #12
MikeLacey
Human being with feelings
 
Join Date: Dec 2006
Location: UK
Posts: 789
Default

Sorry, I was just surprised to see it. Snow leopard *is* UNIX it seems.
__________________
Mike Lacey, Leicestershire, UK
MikeLacey is offline   Reply With Quote
Old 11-26-2009, 06:53 AM   #13
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default

Quote:
Originally Posted by MikeLacey View Post
Sorry, I was just surprised to see it. Snow leopard *is* UNIX it seems.
OSX is unix
klankschap is offline   Reply With Quote
Old 11-26-2009, 06:58 AM   #14
Kainer
Human being with feelings
 
Kainer's Avatar
 
Join Date: Nov 2007
Location: Cologne/Bishkek
Posts: 1,258
Default

Quote:
Originally Posted by schwa View Post
If there is a typical way for OSX users to have both Python v2 and v3 installed, we can maybe have ReaScript look for v3 first.
I would prefer to have this "looking for python 3" in reaper cause I have tried (without any scripting experiences) to tell my mac (the terminal) to use python 3 (I have both versions 2.6 and 3 installed, too) but failed.
Nothing works. I have done step by step instructions to delete python2.6 but my terminal gives me "python2.6.1"-message everytime I type in "Python".

Bash-changing-hyroglyphes are not made for me and my dyslexic brain so I failed to run scripts which require python3.

I don´t know about the typical way OSX installes python but would like to know how to tell reaper to use python 3.

Generally it is a pain in the ass to find data in the library of osx (someone knows how to change the spotlight in a way that it searches in ALL folders instead of only some?) so I spend hours to find out where to look at, how to install and delete and in the end my terminal gives me a "python2.6.1" display anyway.
__________________
I am old here

http://kainerweissmann.de
Kainer is offline   Reply With Quote
Old 11-26-2009, 07:03 AM   #15
EvilDragon
Human being with feelings
 
EvilDragon's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 24,798
Default

Quote:
Originally Posted by schwa View Post
Not really, because it would make the Reaper installer 1.5x bigger for a feature that most people won't use.
Just 6 MB bigger? Bring it on


Really, I have asked myself this too. How about having three separate Reaper versions - one vanilla, one with Python, one with Perl, to be downloaded separately? This would bypass installing the whole Python/Perl thingie on your system and make Reaper entirely self-contained.


As I understand, there is no need to have the whole stuff that's installed with Python/Perl. Because, I saw from another example (it's Ren'py, Python-based visual novel engine) that you don't need to have whole Python installed to make it functional - rather there is one executable that's compiling the scripts on the fly. The size of Ren'py is not big, some 18 MB IIRC.
EvilDragon is online now   Reply With Quote
Old 11-26-2009, 07:04 AM   #16
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,815
Default

Would somebody who has both Python 2 and 3 installed on their mac mind doing this from the terminal and pasting the output?

Code:
find / -name libpython*.dylib -print 2>/dev/null
Thanks.
schwa is offline   Reply With Quote
Old 11-26-2009, 07:18 AM   #17
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default

Quote:
Originally Posted by schwa View Post
Would somebody who has both Python 2 and 3 installed on their mac mind doing this from the terminal and pasting the output?

Code:
find / -name libpython*.dylib -print 2>/dev/null
Thanks.
$ find / -name libpython*.dylib -print 2>/dev/null
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/lib/libpython.dylib
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/lib/libpython2.5.dylib
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/lib/libpython2.dylib
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.2.sdk/usr/lib/libpython.dylib
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.2.sdk/usr/lib/libpython2.5.dylib
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.2.sdk/usr/lib/libpython2.dylib
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/usr/lib/libpython.dylib
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/usr/lib/libpython2.5.dylib
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/usr/lib/libpython2.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/libpython.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/libpython2.5.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/libpython2.dylib
/Developer/SDKs/MacOSX10.6.sdk/usr/lib/libpython.dylib
/Developer/SDKs/MacOSX10.6.sdk/usr/lib/libpython2.5.dylib
/Developer/SDKs/MacOSX10.6.sdk/usr/lib/libpython2.6.dylib
/Library/Frameworks/Python.framework/Versions/3.1/lib/libpython3.1.dylib
/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/libpython2.4.dylib
/usr/lib/libpython.dylib
/usr/lib/libpython2.5.dylib
/usr/lib/libpython2.6.dylib
klankschap is offline   Reply With Quote
Old 11-28-2009, 10:26 AM   #18
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,815
Default

If you have both Python 2 and 3 installed, you can try this in Reaper 3.1415 (released version): locate REAPER.ini, and in the [reaper] section (which is usually the top 50% of the file), add the line

Code:
pythonlib=/Library/Frameworks/Python.framework/Versions/3.1/lib/libpython3.1.dylib
(or whatever is the path to the Python 3 dylib.)
schwa is offline   Reply With Quote
Old 11-28-2009, 03:21 PM   #19
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default

Quote:
Originally Posted by schwa View Post
If you have both Python 2 and 3 installed, you can try this in Reaper 3.1415 (released version): locate REAPER.ini, and in the [reaper] section (which is usually the top 50% of the file), add the line

Code:
pythonlib=/Library/Frameworks/Python.framework/Versions/3.1/lib/libpython3.1.dylib
(or whatever is the path to the Python 3 dylib.)
nope.
not yet.
still get an error:

The test_reaper.py file has this single line in it:
BPR_APITest()

When i run it i get this error:


ReaSScript error: test_reaper.py
Script execution error:
line 1
BPR_APITest()
^
IndentationError: unexpected indent
klankschap is offline   Reply With Quote
Old 11-28-2009, 03:54 PM   #20
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by klankschap View Post

The test_reaper.py file has this single line in it:
BPR_APITest()
The Reaper API functions have to have RPR_ at the beginning in the scripts, not BPR. So it is RPR_APITest()...
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 11-28-2009, 05:20 PM   #21
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default

Quote:
Originally Posted by Xenakios View Post
The Reaper API functions have to have RPR_ at the beginning in the scripts, not BPR. So it is RPR_APITest()...
getting closer (i guess):




Script execution error:

line 43
RPR_APITest()
^
SyntaxError: invalid syntax
klankschap is offline   Reply With Quote
Old 11-30-2009, 12:30 PM   #22
cturner
Human being with feelings
 
cturner's Avatar
 
Join Date: Apr 2009
Location: GWB
Posts: 76
Default

Maybe not too much help, but with Leopard 10.5.8 and the supplied Python 2.5.1, and no Python 3.1 installed, the examples above work fine.

More accurately, the following works fine:

Code:
RPR_APITest()
RPR_ShowConsoleMsg("Dead Beef")
RPR_Main_OnCommand(40012, 0)
The "under mouse cursor" of 40746 was a bit too challenging for me at this point. :-)

HTH, Charles
cturner is offline   Reply With Quote
Old 11-30-2009, 04:52 PM   #23
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default

Quote:
Originally Posted by cturner View Post
Maybe not too much help, but with Leopard 10.5.8 and the supplied Python 2.5.1, and no Python 3.1 installed, the examples above work fine.

More accurately, the following works fine:

Code:
RPR_APITest()
RPR_ShowConsoleMsg("Dead Beef")
RPR_Main_OnCommand(40012, 0)

Well, not here (yet)

for what it is worth, the url
/Library/Frameworks/Python.framework/Versions/3.1/lib/libpython3.1.dylib
is a link to
/Library/Frameworks/Python.framework/Versions/3.1/Python


The error message still points to a non existing line in the script.

F
klankschap is offline   Reply With Quote
Old 11-30-2009, 06:21 PM   #24
cturner
Human being with feelings
 
cturner's Avatar
 
Join Date: Apr 2009
Location: GWB
Posts: 76
Default

Quote:
Originally Posted by klankschap View Post
for what it is worth, the url
/Library/Frameworks/Python.framework/Versions/3.1/lib/libpython3.1.dylib
is a link to
/Library/Frameworks/Python.framework/Versions/3.1/Python
REAPER is probably trying to open the shared library, so I'd stick with the .dylib line.

I've attached my working scripts, in case it's a character encoding issue or somesuch.

HTH, Charles
Attached Files
File Type: zip reascript-py.zip (1.5 KB, 145 views)
cturner is offline   Reply With Quote
Old 11-30-2009, 06:33 PM   #25
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default

Quote:
Originally Posted by cturner View Post
REAPER is probably trying to open the shared library, so I'd stick with the .dylib line.

I've attached my working scripts, in case it's a character encoding issue or somesuch.

HTH, Charles
And a character encoding it seems to be.
Your scripts pass the OK-test.

Now which encoding do we have to use ?
# encoding: utf-8
does not seem to work

F
klankschap is offline   Reply With Quote
Old 11-30-2009, 06:45 PM   #26
cturner
Human being with feelings
 
cturner's Avatar
 
Join Date: Apr 2009
Location: GWB
Posts: 76
Default

Quote:
Originally Posted by klankschap View Post
Now which encoding do we have to use ?
# encoding: utf-8
does not seem to work
What are you editing your scripts in? TextMate here is saving as UTF-8 with Unix LFs (0x0a), although with just the ASCII in those files, I do believe they're indistinguishable from plain text files.

I might look to the line endings. I'm not that facile with Python (been using Ruby up to now) but it might screw up the indentation that Python is expecting if the line endings aren't right.

HTH, Charles
cturner is offline   Reply With Quote
Old 11-30-2009, 07:01 PM   #27
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default

Quote:
Originally Posted by cturner View Post
What are you editing your scripts in? TextMate here is saving as UTF-8 with Unix LFs (0x0a), although with just the ASCII in those files, I do believe they're indistinguishable from plain text files.

I might look to the line endings. I'm not that facile with Python (been using Ruby up to now) but it might screw up the indentation that Python is expecting if the line endings aren't right.

HTH, Charles
TextMate writing UTF-8 needs the Unix LF
It doesn't seem to like the Windows CRLF

but at least i can get some scripting to run.
thanks !
F
klankschap is offline   Reply With Quote
Old 11-30-2009, 08:21 PM   #28
cturner
Human being with feelings
 
cturner's Avatar
 
Join Date: Apr 2009
Location: GWB
Posts: 76
Default

Yeah, looks like Windows CRLF and Mac Classic CRs don't make the ReaScript feature too happy on OSX:





Have fun! Charles
Attached Images
File Type: png crlf.png (20.9 KB, 575 views)
File Type: png cr.png (23.7 KB, 499 views)
cturner is offline   Reply With Quote
Old 12-01-2009, 02:12 AM   #29
klankschap
Human being with feelings
 
Join Date: Feb 2007
Posts: 99
Default

Quote:
Originally Posted by cturner View Post
Yeah, looks like Windows CRLF and Mac Classic CRs don't make the ReaScript feature too happy on OSX:
Well it is the combination OSX + reaper that doesn't like CRLF.
No such problem when using it with OSX + TextMate for instance.

F
klankschap is offline   Reply With Quote
Old 12-01-2009, 07:48 PM   #30
liteon
Human being with feelings
 
liteon's Avatar
 
Join Date: Apr 2008
Posts: 510
Default

only lf and crlf are working on win32 - not cr.
but, my guess is that the "new line" handling routine is the same for all os.
are you sure that crlf isn't working on mac?

in the current set the empty line at the end of input is necessary for the fact that "except SystemExit:" is added there. @ schwa - "\n"+footer perhaps here to ensure. instead of "new line" you can add a "#", which will comment out the handler.

the line number offset from stderr is there, because the interpreter is inserting code before the input as well, e.g.: 43+n
liteon is offline   Reply With Quote
Old 12-01-2009, 08:10 PM   #31
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,815
Default

We will fix the parser to handle various newlines properly.
schwa is offline   Reply With Quote
Old 12-01-2009, 08:17 PM   #32
cturner
Human being with feelings
 
cturner's Avatar
 
Join Date: Apr 2009
Location: GWB
Posts: 76
Default

Quote:
Originally Posted by liteon View Post
are you sure that crlf isn't working on mac?
Well, I got the alert from this file:



The only version that seems to work on OSX-Reaper is LFs-only.

BTW: Many thanks for your JS plug-ins! I was looking for peak limiter code, and I think yours has all I'll ever need. Gotta study...

Best, Charles
Attached Images
File Type: png hexdump.png (24.9 KB, 461 views)
cturner is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:22 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.