Page 1 of 1

[Mac] Python post processing

Posted: January 20th, 2010, 11:37 pm
by zakharm
Has anyone been successful in running Python scripts in the latest 0.5 Beta6 or RC3 on the Mac? 

I have two systems, one running Leopard (Python v2.5) and the other Snow Leopard (python v2.6).  It used to be only the Snow Leopard machine that gave me problems running Python scripts, now it is happening on both systems.

I get these errors on most Python modules that need to be imported.  I've seen these errors throughout the forum, but no solution.

Code: Select all

'import site' failed; use -v for traceback
Traceback (most recent call last):
  File "/Users/zakharm/Documents/scripts/xbmc2.py", line 4, in <module>
    import urllib, sys
ImportError: No module named urllib
Script:

Code: Select all

#!/usr/bin/env python
import urllib, sys
urllib.urlopen("http://192.168.2.51:3000/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)")

Re: [Mac] Python post processing

Posted: January 21st, 2010, 7:42 am
by JohnSCS
This usually relates to the wrong version of Python interpreter being installed for the source code used. There are major differences between Python versions to the point of renamed/deleted functions. I always use 2.6.4 as it has some of the best function support, but scripts written for 2.6.4 will not usually work on 3.0. urllib was replaced with urllib2 in 3.0 but they coexisted in 2.6.4.

Hope that makes sense.


Try this

Code: Select all

#!/usr/bin/env python (not sure about this - double check that this is your Python installed location. Could it be #!/usr/bin/python )
# Python 2.6.4 | http://www.python.org/download/releases/2.6.4/
import socket,sys,urllib2,os
from urllib2 import Request, URLError, urlopen

# HTTP timeout in seconds for url requests
socket.setdefaulttimeout(10)

# Update Video Library on XBMC1
# Set url request
xbmc1=urllib2.Request("http://192.168.0.51:3000/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)")
# Attempt to process request
try: urllib2.urlopen(xbmc1)
# Check for request error
except URLError, e:
# If error - say so :)
        print 'XBMC1 Failed'
Also check http://forums.sabnzbd.org/http://forums ... 147#p22147 for hints.
Unix has proven to be a little difficult at times to get the scripts working :-\ but the script is running for you, its just the module is not loading.

Re: [Mac] Python post processing

Posted: January 21st, 2010, 3:20 pm
by zakharm
Thanks for the reply.

What is the reasoning for my scripts running from Terminal, but not able to be called from SAB?

I even tried to create a shell script wrapper to call Python directly and I had no luck.

As we try to distribute scripts here it would be preferable if the scripts would just run on the stock install of Python on the Mac and not have to upgrade it.

Re: [Mac] Python post processing

Posted: February 1st, 2010, 6:41 pm
by imthenachoman
I was having same problem. I had to change the python path used by SabNZBD.

Look near the top middle of my code:

http://forums.sabnzbd.org/index.php?topic=3562.msg25576

If you cannot find it let me know and I'll help..

Re: [Mac] Python post processing

Posted: February 2nd, 2010, 2:54 pm
by zakharm
imthenachoman wrote: I was having same problem. I had to change the python path used by SabNZBD.

Look near the top middle of my code:

http://forums.sabnzbd.org/index.php?topic=3562.msg25576

If you cannot find it let me know and I'll help..
Great work on finding a solution!  I can get back to programming my scripts in Python.

I assume your paths will only work on Snow Leopard?  I believe my Leopard paths are still for version 2.5 of python.

Re: [Mac] Python post processing

Posted: February 2nd, 2010, 7:17 pm
by imthenachoman
Yeah. Just find the path used for Python on Leopard with 2.5 and use that.
zakharm wrote:
imthenachoman wrote: I was having same problem. I had to change the python path used by SabNZBD.

Look near the top middle of my code:

http://forums.sabnzbd.org/index.php?topic=3562.msg25576

If you cannot find it let me know and I'll help..
Great work on finding a solution!  I can get back to programming my scripts in Python.

I assume your paths will only work on Snow Leopard?  I believe my Leopard paths are still for version 2.5 of python.

Re: [Mac] Python post processing

Posted: February 3rd, 2010, 10:16 am
by zakharm
I haven't tested on my Leopard system, but on Snow Leopard this path fix worked like a charm - nice work!

Re: [Mac] Python post processing

Posted: February 4th, 2010, 5:15 am
by zerointerupt
Still  no joy for me on Leopard,  I've tried using sys.path at the top of script and it still bombs out.  It's annoying as well as the only way I know to test it is after each download. 
So it's a slow trouble shooting process.  I've also tried setting the PYTHONPATH and then editing the plist file to use PYTHONPATH=true.  But to no avail.

I've got 2.6 installed from the package, why can't I get Sab to find the right libraries?

Does anyone have any other suggestions?

Re: [Mac] Python post processing

Posted: February 5th, 2010, 9:56 pm
by imthenachoman
zerointerupt wrote: Still  no joy for me on Leopard,  I've tried using sys.path at the top of script and it still bombs out.  It's annoying as well as the only way I know to test it is after each download. 
So it's a slow trouble shooting process.  I've also tried setting the PYTHONPATH and then editing the plist file to use PYTHONPATH=true.  But to no avail.

I've got 2.6 installed from the package, why can't I get Sab to find the right libraries?

Does anyone have any other suggestions?

From terminal type "python" then in the interactive prompt import sys and print sys.path and use those paths in your script. It aught to work. The only thing I can think would be that SabNZBD is using its compiled in version of python (2.6 I think) in which case 2.5 libraries wont work.