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.

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. Commented May 10, 2016 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. Commented May 11, 2016 at 7:38
  • @Helze: I have updated my answer to reflect your new error message. Commented Aug 5, 2016 at 10:16

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Then your problem is somewhere in the script. Can you please show a little bit more of it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.