This is the first day of my participation in the Gwen Challenge in November. Check out the details: the last Gwen Challenge in 2021.
inMac
Under the default installationPython
isPython 2.7.16
.
This is theMarch 4, 2019
Released version.
It has been more than two years.
The new version of thePython
Basically, it is released regularly on a monthly update schedule.
So far,Python
It’s been releasedPython 3.8.9
Version.
It means to be in theMac
Experience the new versionPython3
Features. You need toMac
Installed on thePython3
And keep updated.
Here we useHomebrew
Install and perform updates.
I. Environment configuration
Check the Mac environment preparations.
1. CheckHomebrew
Because we use Homebrew to install and keep Python up to date. Therefore, we first examine the Homebrew environment.
If the content is not displayed, instead it is displayedcommand not found: brew
. Installation requiredHomebrew
.
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Copy the code
2. View the installed softwarePython
If you have previously installed using Python downloaded from python.org. So it installs and updates differently than Homebrew. If you don’t need multiple old Python versions to exist at the same time, you need to remove the excess Python versions.
Note ⚠️ : inMac
On, the operating system needs to use/usr/bin/python
Under thePython
. So in that directoryPython
Do not delete.However, at/usr/local/bin
Or by symbolic link herePython
Version can be deleted.If the position is../Cellar/python
At the beginning, the instructions are usedHomebrew
The installation.
Unneeded Python versions are simply removed here, and then the original file is deleted.
3. The installationPython
brew install python3
Copy the code
4. UpgradePython
brew upgrade python3
Copy the code
If the latest version is already installedPython
.Homebrew
Will display:
About 5.PYTHONPATH
The environment variable
The PYTHONPATH environment variable is the Python search path, and by default all modules we import will be found from PYTHONPATH.
PYTHONPATH can be printed using the following code:
print(os.sys.path)
Copy the code
I. the configurationLLDB Python
The module
Append the LLDB Python module path to the sys.path list for easy import.
- for
sh
andbash
:
export PYTHONPATH=`lldb -P`
Copy the code
- for
csh
andtcsh
:
setenv PYTHONPATH `lldb -P`
Copy the code
The default Shell for the new macOS is ZSH. So, first enter terminal execution:
echo 'export PYTHONPATH=`lldb -P`' >> ~/.zshrc
Copy the code
Then execute:
source ~/.zshrc
Copy the code
In 6.VS Code
In the configurationPython
I. inVS Code
Installed in thePython
The plug-in
inVSCode
Search extension inPython
, as shown below:
After the installation is complete, you need to load it againVSCode
Enable the plug-in.
Ii. InVS Code
In the configurationPython
The environment
inVS Code
In the⌘ + N
Create a new file and select it in the lower left cornerPython
Interpreter, select in the lower right cornerPlain Text
forPython
:⚠ ️ note:usePython3.0
Previous versions of the interpreter.
Second,pip
Installation and use of
Python has many third-party libraries, or modules. These libraries play different roles for different applications. We will definitely use these modules in real projects. So how do you import these modules into your own projects?
Python’s official PyPi repository provides a unified repository where all third-party libraries, even your own open source modules, can be published and downloaded by the world.
Python has two well-known package management tools:
easy_install
pip
inpython 2
In theeasy_install
Is installed by default, andpip
We need to install it manually. As thePython
Version improvement,easy_install
Has been gradually phased out, but some of the older third-party libraries, in the current can only passeasy_install
Install. At present,pip
Has become a mainstream installation tool since2 > = 2.7.9 Python
orPython 3.4
They are installed by defaultpip
.
Use instructionpip3 -v
For details:
usepip3
Installation module:
pip install requests
pip install ipython
Copy the code
Install modules with piP3 specified version:
PIP install pygame = = 1.9.6Copy the code
Install modules with piP3 specified version:
pip uninstall pygame
Copy the code
List the installed libraries:
pip list
pip freeze
Copy the code
Save the list of installed libraries to a text file:
pip freeze > ./requirements.txt
Copy the code
Batch install libraries based on dependent files:
pip install -r install.txt
Copy the code
Displays information about installed packages:
pip show package
pip show -f package
Copy the code
Upgrade the specified package:
pip install -U package
Copy the code