Can't run programs in terminal



  • Hi there,
    I have created a program in the editor, and was trying to run it in the terminal. As you all know, to run programs in Python you need to install Python. I did that, and I typed this into the terminal to run the program:

    python /root/greeting.py

    "greeting" is the name of my program, and I put the file into the /root directory in the editor. When I hit enter, I get this:

    -ash: python: not found

    Can anyone help me with this? I've looked over the documentation and I can't fix it.



  • Where's your python installation and what's the path?

    root@Omega-17FD:~# which python
    /usr/bin/python
    root@Omega-17FD:~# echo $PATH
    /usr/sbin:/usr/bin:/sbin:/bin
    root@Omega-17FD:~# python -V
    Python 2.7.14
    


  • I don't know I just put "opkg install python3". I tried what you did and it doesn't seems to have installed it at all.
    Again, "-ash: python : not found" .
    Even weirder, when I try to install it again, it says that Python is up to date.



  • Well, then try python3 -V? Might be that python 3 installation just supplies the python3 binary without creating a symlink from python to python3. You can also do that yourself by doing ln -s /usr/bin/python3 /usr/bin/python.



  • @Maximilian-Gerhardt

    Do not symlink like that, python3 and python2 are not compatible, and python is commonly identified as python2

    @Zachary-Haslam
    Use header in your script (first line):

    #!/usr/bin/env python3
    

    Then set executable right (chmod a+x /root/greeting.py) and run it directly:

    /root/greeting.py
    


  • That did the trick! Thanks! But ANOTHER strange thing: this whole time I've been trying to follow Onion's tutorial on the docs to print Temperature Sensor readings to an LCD screen. The file with the code is called "STK09-temperatureLCD" . When I run the code, I get this:

    -ash: /Upload/STK09-temperatureLCD.py: Permission denied

    I put the file in a folder called "Upload". I moved it out of the /root directory, and I can't run the file...

    Sometimes the Omega can be dumb... :'(



  • @Zachary-Haslam
    It's not omega dumb but your knowledge about Linux is not enough for now ;-) You need to add executable right on the file to execute it directly (chmod a+x /path/to/your/python/script.py).



  • (Nice roast!) Thanks for pointing me out there...I tend to blame the hardware really when it's my fault.
    It seemed to have worked, but it is giving me errors with the code. What did I do wrong?

    /Upload/STK09-temperatureLCD.py: line 1: import: not found
    /Upload/STK09-temperatureLCD.py: line 2: import: not found
    /Upload/STK09-temperatureLCD.py: line 3: from: not found
    /Upload/STK09-temperatureLCD.py: line 6: lcdAddress: not found
    /Upload/STK09-temperatureLCD.py: line 9: oneWireGpio: not found
    /Upload/STK09-temperatureLCD.py: line 10: pollingInterval: not found
    /Upload/STK09-temperatureLCD.py: line 13: syntax error: unexpected "("
    root@Omega-9634:~#

    I have all the import code done and in the /Upload file.

    (Please excuse my little knowledge of the Omega...This is taking a while...)



  • Looks like your header is still wrong, see mine (2 first lines of my sample.py):

    #!/usr/bin/python3
    # -*- coding: utf-8 -*-
    

    Check if path /usr/bin/python3 is correct for omega (don't have one to check, right now).



  • Okay. This is what I did:

    1. I did a factory reset to the Omega.
    2. I went back to the documentation and followed all the steps from the beginning.
    3. I came to the blink program called 'STK01-blink'.
    4. I saved 'STK01-blink' to my Omega. I went to the terminal ran the code and IT WORKS!!!!

    Thank you sooooo much for your help, both of you!


Log in to reply
 

Looks like your connection to Onion Community was lost, please wait while we try to reconnect.