Python Forum
Methods of running a script on Linux distro
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Methods of running a script on Linux distro
#5
Quote:rob@linux038:~/Desktop$ sudo chmod +x script
rob@linux038:~/Desktop$
If this worked then it appears you have two copies of script in your desktop. one called script and one called script.py. It doesnt matter whether there is an extension or not, but if you got a prompt and not an error when you ran this, then it did make it executable and you should be able to now do
~/Desktop$ sudo ./script
(Aug-21-2018, 03:31 PM)Vysero Wrote: I have also tried just running the script with python interpreter like: python script.py (py3 interpreter) and I think it ran but I am not sure.
im pretty sure that ubuntu 16.04 defaults python to python2.x and python3 to python3.x. The same is true there. If you get a prompt after running anything, the program ran and is done without error.

Your shebang line (1st comment line) is important when you run a script as an executable in linux. When you put python3 script.py you are running the script under python3 (or whatever it is mapped to). When you run it as an executable, you are telling it to run under what is in the shebang line. This could cause confusion as you might be thinking it is running under py2, when you are really using py2. This is assuming you have not changed the default though or symlinked it elsewhere.
Recommended Tutorials:
Reply


Messages In This Thread
RE: Methods of running a script on Linux distro - by metulburr - Aug-21-2018, 07:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  No Internet connection when running a Python script basil_555 8 699 Mar-11-2024, 11:02 AM
Last Post: snippsat
Question Running Python script through Task Scheduler? Winfried 8 580 Mar-10-2024, 07:24 PM
Last Post: Winfried
  Is possible to run the python command to call python script on linux? cuten222 6 806 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  Help Running Python Script in Mac OS emojistickers 0 368 Nov-20-2023, 01:58 PM
Last Post: emojistickers
  Trying to make a board with turtle, nothing happens when running script Quascia 3 712 Nov-01-2023, 03:11 PM
Last Post: deanhystad
  Python script running under windows over nssm.exe JaroslavZ 0 739 May-12-2023, 09:22 AM
Last Post: JaroslavZ
  Running script with subprocess in another directory paul18fr 1 3,911 Jan-20-2023, 02:33 PM
Last Post: paul18fr
  Running 3rd party libs on Steam Deck (Arch Linux) with restricted access metulburr 0 1,899 Jan-07-2023, 10:41 PM
Last Post: metulburr
  [SOLVED] [Linux] Script in cron stops after first run in loop Winfried 2 951 Nov-16-2022, 07:58 PM
Last Post: Winfried
  How to compile a Python script for a Windows / Linux executable? netanelst 2 1,360 May-24-2022, 07:02 AM
Last Post: netanelst

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020