简体   繁体   English

在 OSX lion/launchd 中,python/serial 坏了

[英]python/serial broken in OSX lion / launchd

I have a launchd entry that worked with OSX 10.6 but that fails with 10.7.我有一个与 OSX 10.6 一起使用但在 10.7 中失败的launchd条目。 It uses python, and it produces an error whilst trying to import serial .它使用 python,并在尝试导入serial时产生错误。 I don't quite understand this, because I've re-downloaded pyserial-2.5 and re-installed it with sudo.我不太明白这一点,因为我已经重新下载了pyserial-2.5并使用 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. (无奈之下,我在我的机器上为 python 的多种口味中的每一种重新安装了它。)作为测试,我可以输入 python 并毫无困难地import serial 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:是第三方非系统 Python 的site-packages目录,可能是使用 python.org 安装程序安装的,而不是 Apple 提供的系统 ZA7F5F35426B9274173Z 的安装程序,它是:

/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 .因此,您很可能正在使用 python.org Python 来安装pyserial ,但正在启动系统 Python 下launchd Check your shell PATH ( echo $PATH ), it probably has:检查您的 shell PATH ( echo $PATH ),它可能有:

/Library/Frameworks/Python.framework/Versions/2.7/bin

in it.在里面。 And try which python .并尝试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:如果您想将 python.org Python 与您的已launchd plist 一起使用,请将其修改为使用右侧 Python 的绝对路径,例如:

/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:如果你想用系统提供的 Python 安装pyserial ,你可以在安装时使用它的绝对路径:

/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 python -S的一些实验表明sys.path没有正确设置,所以我解决了这个问题

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 .知道这很尴尬,因为它是如此具体,但我想我将不得不忍受它,除非或直到我能找到一种方法告诉launched在哪里可以找到东西,因为它是从 launch 调用的。

PS to anyone coming here later: the switch to OSX 10.7 (Lion) changed loads of things. PS 给以后来这里的任何人:切换到 OSX 10.7 (Lion) 改变了很多事情。 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.如果我发现了,我会尝试这样,并在这里发表进一步的评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM