【发布时间】:2016-05-10 14:40:10
【问题描述】:
我有一个关于在 Python 中通过 execfile() 执行脚本的问题
我的主脚本位于home/pi/var/www/html/main.py。我的第二个脚本是home/pi/start.py,包含几个模块。
当我execfile("/home/pi/start.py") 我得到这个错误:
<type 'exceptions.ImportError'> Python 2.7.9: /usr/bin/python
Tue May 10 18:27:41 2016
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
/var/www/html/main.py in ()
207
208 sys.stdout.flush()
209
210 if __name__=="__main__":
=> 211 main()
main = <function main>
/var/www/html/web.py in main()
165
166 if start is not None:
=> 167 execfile("/home/pi/test.py")
168
169 # 1 staat voor laatste uur
builtin execfile = <built-in function execfile>
/home/pi/start.py in ()
2 import time
3 import RPi.GPIO as GPIO
4 import os
5 import sqlite3
6 import Adafruit_DHT
pid undefined
<type 'exceptions.ImportError'>: No module named pid
args = ('No module named pid',)
message = 'No module named pid'
如果有人知道答案,请随时分享。
【问题讨论】:
-
请提供完整的回溯消息,因为
No module named ...对了解您在哪里遇到问题并没有特别帮助,还请注意execfile与运行它不是一回事单独的过程因此任何相对导入都将与原始文件有关。 -
请编辑您的问题,不要为您自己的问题写这样的答案。另外,请说明您的所有进口。你的问题是关于导入模块。
-
@Helze:我已更新我的答案以反映您的新错误消息。