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
tohello_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!