1

I know this question has been asked many times but going over all the solutions, none seem to work for me. I'm sure it's something simple I'm missing but I'm out of ideas.

Here is the script:

#!/usr/local/bin python3.6


def print_stuff(user_input):
    print(user_input)

def user_input(name=None):
    if name is None:
        name = input('What is your name: ')
        return name
    else:
        return name

def main():
    print_stuff(user_input())

if __name__ == "__main__":
    main()

This is obviously super simple and is meant as a test and only to show me that it does execute. When I try to run the script from the terminal, I get a 'command not found' error.

Here is what I know:

Python 3.6

Mac OS X 10.10.5

$ $PATH
-bash: /Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin: No such file or directory

-rwxr-xr-x  1 GeorgeHart  staff  304 Oct 12 05:17 methods.py

Here is what I've tried: Shebang at the top of the script, tried with 'python3.6', 'python3', 'python':

#!/usr/local/bin python3.6

#!/usr/local/bin/python3.6

#!/usr/local/bin/ python3.6

#!/usr/bin python3.6

#!/usr/bin/ python3.6

#!/usr/bin/python3.6

#!/usr/bin/env/ python3.6

That last one gives me a directory error. When I navigate to that path, env is not a directory.

Any thoughts would be greatly appreciated. Let me know if more information is needed.

jimmyscrote
  • 41
  • 1
  • 3
  • 1
    are you running the command with python methods.py? – modesitt Oct 12 '17 at 19:00
  • 1
    Also have you installed python 3.6 with homebrew or some other way? – modesitt Oct 12 '17 at 19:00
  • Sorry forgot to mention that. I'm running the command as 'methods.py' or './methods.py'. Using 'python3 methods.py' words just fine. – jimmyscrote Oct 12 '17 at 19:07
  • And honestly, I don't remember how the current version of Python I'm running was installed. After too many getting started guides, I had done a few different things. I just uninstalled anaconda because I was getting versioning conflicts. And I was JUST looking at Homebrew when I saw your response. If re-install is the answer, I'm game. – jimmyscrote Oct 12 '17 at 19:08
  • is your issue not resolved with just running the script with the python command? – modesitt Oct 12 '17 at 19:09
  • https://stackoverflow.com/questions/2429511/why-do-people-write-usr-bin-env-python-on-the-first-line-of-a-python-script – warvariuc Oct 12 '17 at 19:11
  • Technically, yes it is. However, if what I'm doing should work, I want it to. I want to understand as much as I can. – jimmyscrote Oct 12 '17 at 19:14
  • @warvariuc That was actually very informative. I hadn't seen that response. Still not sure why what I'm doing isn't working. – jimmyscrote Oct 12 '17 at 19:19

2 Answers2

0

Ultimately, I did a clean install of python using Homebrew.

This link was helpful in that respect

Using the shebang:

#!/usr/local/bin/python3

after reinstalling is what is working.

Thanks for the responses.

jimmyscrote
  • 41
  • 1
  • 3
0

Try:

#!/usr/bin/env python3.6

if python3.6 exists in your PATH or

#!/usr/bin/env python3
warvariuc
  • 50,202
  • 34
  • 156
  • 216
  • I had tried that. Ultimately doing a clean reinstall with home-brew got it sorted. Thanks! – jimmyscrote Oct 13 '17 at 18:16
  • In your question the line is different: `/usr/bin/env/` -- with trailing slash, which doesn't work – warvariuc Oct 13 '17 at 18:19
  • Ahh. Looks like I didn’t include that. I had tried what you suggested with no luck. I ultimately got it sorted and posted the answer. Thanks! – jimmyscrote Oct 14 '17 at 20:53