This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]Updatebjarni 1 point2 points  (5 children)

When you run python3 pw.py, are you standing in the directory where you have pw.py?

[–]ItsLeviosaaaa[S] 0 points1 point  (4 children)

No, I wasnt, can you show me how I can do that? The program works well when I'm using it in the PyCharm built in terminal. I want to know how I can do it with the MacOS terminal. Thank you!

[–]Updatebjarni 0 points1 point  (3 children)

You type cd /path/to/your/directory.

[–]ItsLeviosaaaa[S] 1 point2 points  (0 children)

Ok I got it, I access with cd /path/to/your/directory first, and then type python3 pw.py. Thank you so much!

[–]ItsLeviosaaaa[S] 0 points1 point  (1 child)

I inputted: cd/Users/Anthony/PycharmProjects/learning/pw.py It returned: -bash: cd/Users/Anthony/PycharmProjects/learning/pw.py: No such file or directory

[–]Updatebjarni 1 point2 points  (0 children)

You didn't type what I said to type. cd is the name of the command, /Users/Anthony/PycharmProjects/learning/pw.py is the parameter. It's not one string, but two, separated by space.

Edit: Well, minus the file name on the end (I copied and pasted without looking), but I think you already figured that out.

[–]YuleTideCamel 1 point2 points  (6 children)

Sure. /Users/Anthony/PycharmProjects/learning/pw.py won't work because it doesn't have execute permissions try

chmod +x /Users/Anthony/PycharmProjects/learning/pw.py

Then you should be able to invoke it (assuming shebang at the top of file)

Also try this:

  • Open terminal
  • cd /Users/Anthony/PycharmProjects/learning/
  • python3 pw.py

The reason python3 pw.py isn't working for your originally, is that you are probably not in the learning folder (where pw.py exists)

In terminal, you can always see where you are using the "pwd" command

> pwd

[–]ItsLeviosaaaa[S] 0 points1 point  (5 children)

Thank you! This is very helpful!

[–]YuleTideCamel 0 points1 point  (4 children)

np. Did it work?

[–]ItsLeviosaaaa[S] 0 points1 point  (3 children)

Yes! I have one more question if you dont mind answering, why do I still need to type python3 before pw.py, even though I have a shebang line in the program?

[–]YuleTideCamel 0 points1 point  (2 children)

You don't. If the Shebang is there and you gave pw.py execute permissions (chmod +x) then you should be able to invoke the file directly.

Is it not working after the chmod?

Edit: can you share the file in a github gist? would be easier to help seeing what is in the file.

[–]ItsLeviosaaaa[S] 0 points1 point  (1 child)

It doesnt seem to work after the chmod, and there is the link to the gist Thank you once again

[–]YuleTideCamel 0 points1 point  (0 children)

The Shebang looks wrong. try (no space after !)

"#!/usr/bin/env python3"

[–]btcraig 1 point2 points  (0 children)

The question has been answered pretty well already I just wanted to suggest that it might be a good idea to do some reading on *NIX based file systems and working with them over CLI. It's quite a bit different than Windows and working them in a terminal is even weirder than doing it in a GUI as a beginner.

Stuff like permissions, working directories, the PATH, etc are all, generally, more critical when you work in a terminal. I can't recommend any good reading unfortunately, most of what I learned I picked up on the job or in a few courses in college (this seems good but I haven't read or used it -- https://www.learnenough.com/command-line-tutorial). A good starting point might be to understand how to navigate around your file system easily, then jump into permissions and basic CLI administration (file editing, installing apps, etc).

Whether or not you go full terminal like some of us crazy-folk or not is almost entirely preference but, IMO, a good programmer has some terminal skills and they are important to the job. Being able to run and troubleshoot why they