Python 2.7 will reach the end of its life on January 1st, Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of PIP will drop Support for Python 2.7. Many of you will get a warning when using Python, after all, 2020. Our lovely and dedicated Python 2.7 will be out of the way. Continuous update is also continuous functional sound and perfect! Today, I also replaced Python 3.7.3, and the experience is good. There is no problem for the time being

Install python3

Download and install

  • 1. The download address is python 3.7

  • 2. Click the downloaded PKG file to install it

  • 3, after the installation is complete, python 3.70 default installation path is as follows: / Library/Frameworks/python framework Versions / 3.7

  • 4. Modify the profile

In terminal, run open ~/. Bash_profile, open ~/. Bash_profile, and modify the file directly

open  ~/.bash_profile
Copy the code
  • 4.1. Modification Method – Add
alias python="/ Library/Frameworks/Python framework Versions / 3.7 / bin/python3.7"
Copy the code

Or:

source ~/.bash_profile
# Setting PATH for Python 3.7

# The original version is saved in .bash_profile.pysave

export PATH=$PATH: / Library/Frameworks/Python framework/Versions / 3.7 / bin:alias python="/ Library/Frameworks/Python framework Versions / 3.7 / bin/python3.7"
Copy the code
  • 5. Restart Terminal to make the modified file take effect.

Switching between Python 2.7 and Python 3.7

With Python 2.7, comment out version 3.7 in the ~/.bash_profile file directly, i.e

# aliaspython = "/ Library/Frameworks/Python framework Versions / 3.7 / bin/python3.7"
Copy the code

When using Python 3.7, directly open version 3.7 in the ~/.bash_profile file, that is

aliaspython="/ Library/Frameworks/Python framework Versions / 3.7 / bin/python3.7"
Copy the code

Install Homebrew

Homebrew is a software package management tool based on the Mac OS platform. It has many practical functions such as installation, uninstallation, update, view, search and so on. Package management can be implemented with a simple command, and you don’t have to worry about dependencies and file paths. It is very convenient and quick. In a word: It’s great to use

requirements

  • Xcode command line toolxcode-select --install
  • Support for shell (sh or bash)

Installation and uninstallation

  • The installation
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Copy the code
  • Uninstall (I don’t think you need to uninstall after installing)
$ cd `brew --prefix`
$ rm -rf Cellar
$ brew prune
$ rm `git ls-files`
$ rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
$ rm -rf .git
$ rm -rf ~/Library/Caches/Homebrew
Copy the code

Basic use of Homebrew

  • Install any package (super easy)
Brew install <packageName> For example, install node $brew install nodeCopy the code
  • Uninstall packages
$brew uninstall <packageName> For example, uninstall node $brew uninstall NodeCopy the code
  • Other Homebrew commands
$brew search <packageName> * View the list of installed packages $brew List * View any package information $brew info <packageName> * Update Homebrew $brew update * View the Homebrew version $BREW-V * Homebrew help information $brew-hCopy the code

Install python

Brew Search python3 brew install python3 45 degrees look up at the skyCopy the code

OK, you can see the actual installation directory python3 is/usr/local/Cellar/python / 3.7.3

Because you need it every timepython3I felt a little nauseous, so I renamed itpython

  • 4. Open the configuration file and write python’s external environment variables
open ~/.bash_profile
Copy the code
  • Rename Python
alias python="/ usr/local/Cellar/python / 3.7.3 / Frameworks/python framework Versions / 3.7 / bin/python3.7"
Copy the code
  • 6. Let the configuration file take effect
source ~/.bash_profile
Copy the code
  • 7. Restart the PC and run the Python command
python
Copy the code

What Python does – iOS developers can emulate a Python server themselves

Instlal Flask Install the Flask framework (Python web framework) PIP List

  • Import the relevant libraries and start a simple code

  • Configure the execution environment for Xcode – Python

  • Select the Python location

  • Creating a Python file

  • Tool path Setting