我想要做的是在Raspbian启动上执行python脚本。我这样做的方法是:
#!/bin/sh -e
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
/usr/bin/python /home/pi/Desktop/MyProj/sample/main.py > /home/pi/Desktop/projStartup.log 2>&1 &
exit 0
基本上,它的编写方式意味着我将它作为一个分叉的过程启动(最后是'&'),并且每个日志都应放入 projStartup.log >文件。
当我打开终端并输入:
pi@raspberrypi:~ $ /etc/rc.local
一切正常,但是当我尝试重新启动Raspbian时,出现以下错误(错误堆栈顶部):
File "/home/pi/Desktop/MyProj/sample/firebaseManager.py", line 1, in <module>
from pyrebase import pyrebase
File "/usr/local/lib/python2.7/dist-packages/pyrebase/__init__.py", line 1, in <module>
from .pyrebase import initialize_app
File "/usr/local/lib/python2.7/dist-packages/pyrebase/pyrebase.py", line 17, in <module>
from oauth2client.service_account import ServiceAccountCredentials
File "/usr/local/lib/python2.7/dist-packages/oauth2client/service_account.py", line 26, in <module>
from oauth2client import crypt
File "/usr/local/lib/python2.7/dist-packages/oauth2client/crypt.py", line 23, in <module>
from oauth2client import _pure_python_crypt
File "/usr/local/lib/python2.7/dist-packages/oauth2client/_pure_python_crypt.py", line 24, in <module>
from pyasn1_modules.rfc2459 import Certificate
File "/usr/local/lib/python2.7/dist-packages/pyasn1_modules/rfc2459.py", line 20, in <module>
from pyasn1.type import opentype
ImportError: cannot import name opentype
如您所见, opentype 的导入存在问题。我的脚本正在使用的其他模块也有类似的问题,解决方案是使用以下命令在全局安装它们:
sudo pip install ...
因此,现在我想知道需要在全局级别上进行哪些更新才能避免此opentype问题。
答案 0 :(得分:1)
由@thebjorn建议
解决方案:对我来说,解决方案是显式设置pi用户(登录时使用的用户)。
$ python -m smtpd -n -c DebuggingServer localhost:1025
---------- MESSAGE FOLLOWS ----------
Content-Type: multipart/alternative; boundary="===============2742770895617986609=="
MIME-Version: 1.0
Subject: Hello
To: a@example.com
From: b@example.com
X-Peer: 127.0.0.1
--===============2742770895617986609==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Hello World
--===============2742770895617986609==
Content-Type: text/html; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
<p>Hello World</p>
--===============2742770895617986609==--
------------ END MESSAGE ------------