[BUG] Python path in post-processing is wrong

Questions and bug reports for Beta releases should be posted here.
Forum rules
Help us help you:
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
zakharm
Release Testers
Release Testers
Posts: 56
Joined: September 29th, 2008, 1:08 pm

[BUG] Python path in post-processing is wrong

Post by zakharm »

We've been bouncing this around in the post-processing forum, but don't know if it has been officially reported as a bug.  imthenachoman has found a solution, but the solution will need to change for each version of OS X and make writing Python a lot harder across multiple systems (and longer code).  I write my scripts for OS X, Win, Linux.

Python path in post-processing is wrong, "import [module] failed"

Version: 0.5 RC3-RC6
OS: OS X Leopard, OS X Snow Leopard
Install-type: OSx .app
Skin (if applicable): Plush
Firewall Software: None
Are you using IPV6? no
Is the issue reproducible? yes

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.

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

#!/usr/bin/env python
import urllib, sys
urllib.urlopen("http://192.168.2.51:3000/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)")
More detail, please see:
http://forums.sabnzbd.org/index.php?topic=3451.0

Solution from imthenachoman:
I was having same problem. I had to change the python path used by SabNZBD.

Look near the top middle of imthenachnoman's code:
http://forums.sabnzbd.org/index.php?topic=3562.msg25576

Code: Select all

import sys

# This script does not work well with the current default python path SabNZBD sets
# Set it to the same python path as OS X defaults
osx_python_path = [
    sys.path[0],
    "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip",
    "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6",
    "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin",
    "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac",
    "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages",
    "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python",
    "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk",
    "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old",
    "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload",
    "/Library/Python/2.6/site-packages",
    "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC",
    "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode"
]

sys.path = osx_python_path
Write album art post processing script
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: [BUG] Python path in post-processing is wrong

Post by shypike »

It looks like this something Snow Leopards Python causes.
The app is built on Snow Leopard.
The script gets the wrong PYTHONPATH and PYTHONHOME environment variables,
the ones of the "embedded" Python.
I'm not sure we can fix this.

There is a work-around possible.
You'll need to make a wrapper script:

Code: Select all

#!/bin/sh
unset PYTHONPATH
unset PYTHONHOME
/full-path-to-your/python-script.py $*
zakharm
Release Testers
Release Testers
Posts: 56
Joined: September 29th, 2008, 1:08 pm

Re: [BUG] Python path in post-processing is wrong

Post by zakharm »

Thanks, I'll give that a try.
Write album art post processing script
Post Reply