1

I have a question about executing a script via execfile() in Python

My main script is located at home/pi/var/www/html/main.py. My second script is home/pi/start.py and includes several modules.

When I execfile("/home/pi/start.py") I get this error:

<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'

If someone know the answer feel free to share.

MERose
  • 4,048
  • 7
  • 53
  • 79
Helze
  • 11
  • 3
  • Please provide the full traceback message as `No module named ...` is not particularly helpful in understanding where you are running into problems, also note that `execfile` is *not the same thing as running it as a seperate process* So any relative imports would be with respect to the original file. – Tadhg McDonald-Jensen May 10 '16 at 16:23
  • Please edit your question and don't write an answer like this to your own question. Also, please state all of your imports. Your problem is about importing modules. – MERose May 11 '16 at 07:38
  • @Helze: I have updated my answer to reflect your new error message. – MERose Aug 05 '16 at 10:16

1 Answers1

0

The problem is clearly with your imports and has nothing to do with execlfile().

Either RPi.GPI or Adafruit_DHT requires the python package pid as dependency. Simply install it: pip install pid. Or re-install the said packages again. pip usually takes care of dependencies as well.

MERose
  • 4,048
  • 7
  • 53
  • 79