All you have to do when wishing to run your Python script against the default system Python (2.7.10) provided by Apple is to ensure that the PYTHONPATH environment variable is unset, and run:
python foo.py
or, if the first line in your script is #!/usr/bin/python and the script is executable:
./foo.py
If you have installed Python from another source, let's say Python 2.7.14 from Python dot org, then its binaries will be in /usr/local/bin, and the required library location is at /Library/Frameworks/Python.framework/Versions/2.7/lib. To use this version of Python, instead of the System Python, you do the following:
set the PYTHONPATH environment variable to "/Library/Frameworks/Python.framework/Versions/2.7/lib" and change the first line of your Python script to:
#!/usr/bin/env python
Now, the script will look at PYTHONPATH, and use Python 2.7.14, instead of the default System Python 2.7.10. If you unset the PYTHONPATH environment variable, then the script will revert to using the System Python 2.7.10.
If however, you installed Python 3.6.3 from Python dot org, then you would have to use the appropriate change in PYTHONPATH for 3.6/lib, and change the first line of the script to #!/usr/bin/env python3.
All of this assumes that your Terminal PATH settings are properly set.
The following Python script will print out the current version of Python:
#!/usr/bin/env python
import platform
import sys
print(platform.python_version())
sys.exit()