python/serial broken in OSX lion / launchd
I have a launchd
entry that worked with OSX 10.6 but that fails with 10.7. It uses python, and it pro开发者_如何学运维duces an error whilst trying to import serial
. I don't quite understand this, because I've re-downloaded pyserial-2.5
and re-installed it with sudo. (In desperation, I re-installed it for each of the many flavours of python on my machine.) As a test, I can enter python and do import serial
without difficulties. Maybe there is a system path that is set up well for an interactive user, that is not set up for launched??
Can anyone suggest how I might diagnose the problem?
The path you are appending:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
is the site-packages
directory for a third-party, non-system Python, possibly installed using a python.org installer, and not that of the Apple-supplied system Python 2.7, which would be:
/Library/Python/2.7/site-packages
So most likely you are using the python.org Python to install pyserial
but are launching the system Python under launchd
. Check your shell PATH
(echo $PATH
), it probably has:
/Library/Frameworks/Python.framework/Versions/2.7/bin
in it. And try which python
. If you want to use the python.org Python with your launchd
plist, modify it to use an absolute path to the right Python, for instance:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
If you want to install pyserial
with the system supplied Python, you can use an absolute path to it when doing the install:
/usr/bin/python2.7
Some experimentation with python -S
showed me that the sys.path
was not set up properly, so I solved the issue by
import sys
sys.path.append('/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages')
import serial
which I know is awkward, since it is so specific, but I guess I'll have to live with that, unless or until I can find a way to tell python where to find things, as it is being invoked from launched
.
PS to anyone coming here later: the switch to OSX 10.7 (Lion) changed loads of things. Perhaps I had some initialization file somewhere, that I forgot about. If I find that, I'll try it that way, and post a further comment here.
精彩评论