Jump to content

Shebang line/terminal/calling on python files

- - - - -

  • Please log in to reply
3 replies to this topic

#1
demo53

demo53

    Newbie

  • Members
  • PipPip
  • 10 posts
How come when I run python programs from terminal, I have to write "python file.py" or "python3.2 file.py" ? If I'm including a shebang line specifying that the program should be opened with python 3.2 interpreter, shouldn't it automatically open with python3.2 w/o specifying "python3.2 file.py". Shouldn't I just only have to specify the file name, "file.py"?

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
What is the very first line in your file.py?

Some shells are picky on how it is formed, you may wish to check the format and paths as well. You may need to set it as an executable first, i.e.
chmod +x file.py
./file.py

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
demo53

demo53

    Newbie

  • Members
  • PipPip
  • 10 posts
Haha, yeah I forgot you had to do "./file.py" I felt like I was forgetting something, but couldn't think of what it was.

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
Glad you could get it to work!
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users