0

I have tried to gather as much information as possible before posting this question but have had little luck. (I posted the links below.)

I have a file called "Intro.py" at this path, "programming/py_projects/Incubator/Course".

I have a file called "Python.command" on my desktop. Within the command file I have the following lines:

cd ../programming/py_projects/Incubator/Course
bash python Intro.py

When I run the command file (double click), terminal opens and this is the result:

/Users/muhs_a/Desktop/Python.command: line 1: cd: ../programming
/py_projects/Incubator/course: No such file or directory
/usr/bin/python: /use/bin/python: cannot execute binary file
logout

I just want to be able to double click on the Python.command file and have the program written in Intro.py to run in the terminal. Where am I going wrong?

How to create a batch file in mac?
Why do people write #!/usr/bin/env python on the first line of a Python script?
How do I make this file.sh executable via double click?

Community
  • 1
  • 1
  • Make sure that the file opens with terminal. Right click, get info, open with. To give a file execute permissions. Open terminal type in chmod +x pathtofile. – reticentroot Apr 01 '15 at 00:22
  • If I had to guess, I'd say that the directory `../programming/py_projects/Incubator/course` doesn't exist from the context of the location from which you call this `.command` file. – TigerhawkT3 Apr 01 '15 at 00:22
  • Also why don't you just write a shell file. See here http://stackoverflow.com/questions/29338066/mac-osx-execute-a-python-script-at-startup – reticentroot Apr 01 '15 at 00:23
  • @msanti It does open with terminal and tries to run. I just get what is shown above. I'll take a look at the link. Thanks. –  Apr 01 '15 at 00:29
  • @TigerhawkT3 What do you mean, "...from the context of the location from which you call this .command file"? –  Apr 01 '15 at 00:31
  • I just meant your present working directory when you call this file - important for relative paths. Also check the case: the given content of the `.command` file says `Course`, but the error says `course`. – TigerhawkT3 Apr 01 '15 at 00:37
  • I changed the top line to : cd ~/Programming/py_projects/Incubator/Course The error now only has the line that says /usr/bin/python: /use/bin/python: cannot execute binary file –  Apr 01 '15 at 01:10

2 Answers2

1

Open up the Terminal and run chmod +x ~/programming/py_projects/Incubator/Course (I'm assuming that the directory programming is in your home dir). This command changes the permissions on your script to make it executable.

pzp
  • 5,751
  • 1
  • 24
  • 36
  • Just ran it. Still no luck. –  Apr 01 '15 at 01:03
  • I changed the top line to : cd ~/Programming/py_projects/Incubator/Course The error now only has the line that says /usr/bin/python: /use/bin/python: cannot execute binary file –  Apr 01 '15 at 01:07
0

I figured it out. I changed my Python.command file to:

#!/bin/bash
python ~/Programming/py_projects/Incubator/Course

I then got an error that said:

/usr/bin/python: can't find '__main__' module in...

I then changed the name of the file from Intro.py to reflect the missing module and it runs perfectly.

  • If you just want to run the script in Terminal you can just run ```python ~/Programming/py_projects/Incubator/Course``` directly from the command line. No need for an extra command file. – pzp Apr 01 '15 at 02:58
  • 1
    Right. I wanted to use the command file. I am trying to learn how these things work. Thank you though. –  Apr 02 '15 at 03:07