4 Replies Latest reply on Oct 8, 2015 1:24 PM by mhahn

    What a silly python question


      I am trying to code using python on the Edison (from the IOT XDK).


      I can run the classic "hello World" using python from the command line; however I cannot make it work from within a script. I know it seems simple to most but I am pulling my hair out.


      Here is my script file:




      print("Python running on Edison")


      I get the following after saving and downloading to Edison:



      |    Intel (R) IoT - NPM Install - (may take several minutes)                                                                                                             


      npm WARN package.json SimpleTest@0.0.0 No description                                                                                                                     

      npm WARN package.json SimpleTest@0.0.0 No repository field.                                                                                                              

      npm WARN package.json SimpleTest@0.0.0 No README data                                                                                                                    


      |    NPM INSTALL COMPLETE![ 0 ]  [ 0 ]                                                                                                                                  



      Intel XDK - Message Received: run                                                                                                                                        

      => Stopping App <=                                                                                                                                                        


      ERROR: /home/root/.node_app_slot/main.py:2                                                                                                                                

      ERROR: print("Python running on Edison")                                                                                                                                  

      ERROR: ^                                                                                                                                                                  

      ERROR: ReferenceError: print is not defined                                                                                                                               

          at Object.<anonymous> (/home/root/.node_app_slot/main.py:2:1)                                                                                                        

          at Module._compile (module.js:456:26)                                                                                                                                

          at Object.Module._extensions..js (module.js:474:10)                                                                                                                  

          at Module.load (module.js:356:32)                                                                                                                                    

          at Function.Module._load (module.js:312:12)                                                                                                                          

          at Function.Module.runMain (module.js:497:10)                                                                                                                        

          at startup (node.js:119:16)                                                                                                                                          

          at node.js:935:3    


            I get the feeling that I am not really executing the script with python, but have no idea. If I insert a comment line (#) as the second line, that line show up with the error.


      Any help would be appreciated.



        • 1. Re: What a silly python question

          hard to say what you do without knowing exactly what you do.


          • how did you try to start the python program?
            • within XDK? If yes, how?
            • trying to run as a Node.JS app?
          • if you set your script executable (chmod +x main.py) and run it from console (./main.py) it will work just fine
          • 2. Re: What a silly python question



            You can also run the Python script using the following command:

            • python main.py




            • 3. Re: What a silly python question

              Thank you Mahan and Diego,


              I am using the IOT XDK and yes, I did try to run the python script from the XDK interface. This is the way I have ben testing my node.js scripts and all seems to work when I do this. I was under the impression that I could create code for any of the supported languages (including python) and execute them the same way during debugging.


              I do not understand all of the additional detail after the "ReferenceError", but I suppose it is trying to tell me exactly where the command failed.


              I mentioned that the error seems to indicate that an interpreter other than python is looking at the script. Just my feeling since it is such a simple script. I thought that the hashbang (line 1) code was supposed to tell the system which interpreter to use on the script. I still seem to be misunderstanding something if the XDK cannot run this script.


              I really only selected python to use as I have seen various code snippits that deal with Bluetooth using python to automate device selection.


              Thanks again fro your quick responses,



              • 4. Re: What a silly python question

                while you obviously can run Python code from the XDK ssh console for the target system the IDE itself IMHO is only supporting Javascript (Node.JS resp) [besides CSS / HTML].

                But you surely can run your Python scripts on the target and communicate with XDK Node.JS code