In general, the Linux system comes with a python development environment installed by default. But if your Linux does not install python, you can learn how to install it in this article. We will introduce how to install python Linux version on Ubuntu and how to install python on macOS step by step.
1. How To Install Python On Linux.
- Start the command line window through the terminal of the system (you can use the shortcut key
"CT + Alt + T") and enter the
pythoncommand in the command line window (note that the letter P is lowercase).
$ python Python 3.7.4 (default, Aug 13 2019, 15:17:50) [Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
- The above command line shows the python prompt (>>>), which indicates that the python development environment already exists on the Ubuntu system.
pythoncommand start the interactive interpreter of Python. If you want to exit the interactive interpreter, you can press the
"Ctrl + D"shortcut or run
- If you want to check whether python3 is installed on the Ubuntu system or not, you can enter python3 in the terminal command line window.
$ python3 Python 3.7.4 (default, Aug 13 2019, 15:17:50) [Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
- If the python prompt (>>>) is also displayed on the above command line, it indicates that the python 3 development environment already exists on the Ubuntu system. Execute the
python3command to start the python 3 development environment.
- If you think the built-in version of Python 3 in Ubuntu is not newer enough, or you want to install the specified version of Python interactive interpreter, you can execute the following two simple commands.
sudo apt-get update sudo apt-get install python3.7
- The first command above will update the source addresses listed in
/etc/apt/sources.list.dfile to get the latest software package. The second command will install Python 3.7
- After successfully executing the above command, enter the
python3command again in the terminal command line window, and you can see the python version has been updated.
2. How To Install Python On MacOS.
- The latest version of the Mac OS X system usually has Python 2 installed.
- To check whether python is installed in the macOS system or not, start a terminal and enter the
pythoncommand in the terminal window of the system, and you will see the system prompt that python2x has been installed successfully.
$ python Python 2.8.1 (default, Aug 13 2019, 15:17:50) [Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
- If you want to check whether python3 is installed on Mac OS X, you can enter the
python3command in the terminal window. If the system prompts “command not found”, it means that the system has not installed python3 yet.
- To install Python 3 on Mac OS X, follow below steps.
- Go to https://www.python.org/downloads/. Look for the python version that you need in the “Looking for a specific release ?” area, click the download link at the end of the version line. It will open the download page. Scroll down to the end of the page, click macOS 64-bit Intel installer to download the installer which is a .pkg package file.
- Double click the .pkg package file to open the python installation wizard.
- Follow the installation wizard to install python step by step, and leave everything by default.
- After installation, both python 3x and python 2x will exist on the macOS. Enter
pythondirectly in the command line window will run python 2, enter
python3in the command line window will execute python 3.
- You can read the article Installed Python 3 On Mac OS X But It Still Use Python 2.7 if you meet such error.