how to open python 2.7 on mac (using terminal)

Hello, I am trying to use python on my MacBook. I don't think I need the newest version of python so I don't think I have to download anything because I know python 2.7 is already installed on my mac. How do I open python 2.7 so I can start using it??

Macbook (2016 or later)

Posted on Jan 4, 2019 3:10 AM

Reply
1 reply

Jan 4, 2019 6:38 AM in response to lucie2001

Python 2.7.10, which Apple has not updated since El Capitan, is installed by the operating system. You will either use it interactively to test/debug lines of code by running the Python idle utility (in the background) in a separate window to free up a Terminal window; on the command-line for short interactive one-liners, or as multi-line scripts created with a Python-aware programmer's editor. Here is an idle session. Press a return when you first enter it. Idle is built with Tcl and Apple's implmentation is years out of date.

Use control-D to exit idle.


Command-Line



Scripts


You build a Python script in one of two ways. Either a standalone script that references the Python interpreter within it, and externally is made executable via chmod +x code.py:

#!/usr/bin/python


or without. If without, then it is executed as:

python code.py


As for editors, I use Sublime Text 3 with an added Python lint package named Anaconda which interactively flags Python errors and usage issues. There is an open-ended eval period on this programmer's editor. You could get by with BBEdit, which after its trial period, reverts to a free editor with lesser, but sufficient features. And if you demand an improved UNIX vi editor experience, then there is MacVim. Python is fussy about its indentation, and if you use the wrong (TextEdit) tool that does not understand Python indentation, then you will suffer.


The following code (nsa.py):




when saved, and run with an integer argument (nsa.py 35), will produce the following alert dialog:



You can usually find the information you need regarding Python at python.org and the latest Python 2.7 (2.7.15) help. You can also use a search string in a browser: python 2.7 list comprehension and you will see how others use list comprehension.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

how to open python 2.7 on mac (using terminal)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.