
You can add a variety of preferences to the bash profile, including modifications to the PATH. The bash profile is a set of instructions that are run by the shell when the user logs in to bash. When the shell finds that command, it stops and calls it even if there is another version of the same command, with the same name, further down in the list. When you ask your shell to run a particular command or run an interpreter, python for example, the shell looks through the different directories listed in the PATH in order they’re presented above.
/Library/Frameworks/amework/Versions/3.6/bin. /Library/Frameworks/amework/Versions/2.7/bin. /Library/Frameworks/amework/Versions/3.7/bin. The directories above are separated by a colon, this is what they look like displayed in sequence: Library/Frameworks/amework/Versions/3.7/bin:/Users/username/anaconda3/bin:/Library/Frameworks/amework/Versions/2.7/bin:/Users/username/miniconda2/bin:/Users/username/miniconda3/bin:/Library/Frameworks/amework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/X11/bin:/usr/local/git/bin You can display the path on your computer using the echo $PATH command: $ echo $PATH You can also execute Python directly on the cli using the -c option.The path is a list of directories that your shell will look through when you execute a command. Then you can run Python commands directly in the shell. You can open a Python shell simply by typing python or python3 into a Terminal window. You can make your script executable, like this: chmod +x myscript.pyĪnd execute it like this. If your Python script includes a “shebang” ( #!/usr/bin/env python or #!/usr/bin/env python3). Python3 myscript.py Making a Python script executable Simply call python and pass the name of your script, like this: python myscript.py Running a script using the python program is easy, and it's probably the method most people are familiar with. Or you can make the script executable, and call it directly. You can call the python program directly, and pass the name of the script to execute.
There are two common ways to run a Python script from the command line. Mac users can run Python scripts using Terminal.