Page 1 of 1

[BUG] Python path in post-processing is wrong

Posted: February 15th, 2010, 10:11 am
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

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

Posted: February 15th, 2010, 3:19 pm
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 $*

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

Posted: February 15th, 2010, 6:43 pm
by zakharm
Thanks, I'll give that a try.