Python Tutorial

Python Variable

Python Operators

Python Sequence

Python String

Python Flow Control

Python Functions

Python Class and Object

Python Class Members (properties and methods)

Python Exception Handling

Python Modules

Python File Operations (I/O)

Install Python On Mac OS

Similar to Linux distributions, the latest version of Mac OS X also comes with Python 2.x by default.

We can enter the python command in the Terminal window to detect whether the Python development environment is installed, and which version is installed, as follows:
www.iditect.com:~ mozhiyan$ python
Python 2.7.10 (default, Jul 30 2016, 18:31:42)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
It can be seen that the python command can run normally and output the version information of Python, which indicates that the current Mac OS X system already comes with Python 2.7.10.

The python command points to the Python 2.x development environment by default. If you want to detect whether Python 3.x is currently installed on Mac OS X, you can enter the python3 command in the Terminal window:
  • If the system prompts command not found , it means that Python 3.x is not installed.
  • If the python3 command runs successfully and displays the version information, it means that Python 3.x has been installed.

For Mac OS X without Python 3.x installed, it is also very easy to install. Users only need to download the installation package, and then keep "Next", which is very similar to the process of installing Python on Windows.

Install Python 3.x on Mac OS X

Python official download address: https://www.python.org/downloads/

Open the link, you can see the various versions of Python:



Click the version number in the above picture or the "Download" button to enter the download page of the corresponding version, scroll to the end You can see the Python installation package for each platform.



macOS 64-bit installer is the Python installation package for Mac OS X system. Click this link and get a python-3.8.1-macosx10.9.pkg installation package after the download is complete.

Double-click python-3.8.1-macosx10.9.pkg to enter the Python installation wizard, and then follow the wizard to install step by step, keeping everything by default.

After the installation is complete, both Python 3.x and Python 2.x operating environments will exist on your Mac OS X. Entering the python command in Terminal will enter the Python 2.x development environment. Entering the python3 command in Terminal will enter the Python 3.x development environment.
www.iditect.com:~ mozhiyan$ python3
Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>