0

New Python programmer here! Following the answer, I tried to make an executable .py file on MacOS following these steps:

  • Installed Homebrew via MacOS Terminal ($ /usr/bin/ruby-e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)")
  • Installed Python3 from Homebrew (brew install python3)
  • Installed required modules (e.g. python3.7 -m pip install pyfiglet)

Then, I created a simple hello_world.py file:

#!/usr/bin/env python
python import pyfiglet
print(pyfiglet.figlet_format("Hello world!"))
input("Press any key to exit.")

Next, following these instructions,

  • I renamed the file from hello_world.py to hello_world.command
  • From terminal, I entered $ cd Desktop/python to my python projects folder
  • Granted permission chmod +x hello_world.command to the file.

This made the python script executable, and double-clicking it opened a terminal window. However, I get the traceback ImportError: No module named pyfiglet.

I have confirmed pyfiglet is installed and works successfully when I paste the code directly into terminal using python3.7. Anyone know why the .command executable doesn't work? I followed these steps to the letter as described in this answer. Thanks for your help!

EthanAlvaree
  • 103
  • 5
  • 1
    I suspect you are picking up the wrong version of python. Either change the shebang of the script to `#!/usr/local/bin/python3` or set the Homebrew `python3` as [the default for the system](https://stackoverflow.com/questions/49704364/make-python3-as-my-default-python-on-mac). – trojanfoe Sep 20 '19 at 08:09
  • This worked! Thank you! – EthanAlvaree Sep 23 '19 at 17:54

0 Answers0