【问题标题】:No module named ... When I call a script via execfile(pyscript)没有名为的模块...当我通过 execfile(pyscript) 调用脚本时
【发布时间】: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:我已更新我的答案以反映您的新错误消息。

标签: python execfile


【解决方案1】:

问题显然与您的导入有关,与 execlfile() 无关。

RPi.GPIAdafruit_DHT 都需要 python 包 pid 作为依赖项。只需安装它:pip install pid。或者重新安装上述软件包。 pip 通常也会处理依赖关系。

【讨论】:

  • 那么你的问题出在脚本的某个地方。能不能多展示一点?
猜你喜欢
  • 1970-01-01
  • 2020-12-08
  • 1970-01-01
  • 1970-01-01
  • 2018-03-07
  • 1970-01-01
  • 2022-07-20
  • 2015-02-14
  • 2021-09-12
相关资源
最近更新 更多