I am trying to run a Python program from my command line on my Mac. (in this case: python3 Hello.py).
For the life of me, I can’t get it to consider the PATH where the program is located. This is the error message:
/Library/Frameworks/Python.framework/Versions/3.13/Resources/Python.app/Contents/MacOS/Python: can't open file '/Users/user/Hello.py': [Errno 2] No such file or directory.
I have changed the ~/.zshrc file to add the PATH, but it doesn’t work. Here it is:
PATH="/Users/user/mu_code:${PATH}"
export PATH}.
Are there any resources for me to check out?
The path to the file contains an underscore, so I have put the path in “”. Nonetheless it can’t find it. If I type in the full path with the program name, it works fine. Ie.
{python3 /Users/user/mu_code/Hello.py}
works fine.
Python is also in the path already automatically after installation. Here is the path (it's in ~/.zprofile):
PATH="/Library/Frameworks/Python.framework/Versions/3.13/bin:${PATH}"
export PATH
Here is the script of the program with shebang.
{
This program says hello and asks for my name
#!/usr/bin/env python3 print('Hello world') print('Whats your name') myName = input() print('Its good to meet you,' + myName) print('The length of your name is:') print(len(myName)) print('Whats your age?') myAge = input() print('You will be ' + str(int(myAge)+1) + ' in a year')
}
# This program says hello and asks for my name
#!/usr/bin/env python3
print('Hello world')
print('Whats your name')
myName = input()
print('Its good to meet you,' + myName)
print('The length of your name is:')
print(len(myName))
print('Whats your age?')
myAge = input()
print('You will be ' + str(int(myAge)+1) + ' in a year')