Regular play
First introduce a conventional gameplay, and go to the official Python website to download the installation package.
Enter "python" in Bing search, the first search result is what we want:
- Click Downloads directly to jump to the download page
- On the download page, click on the note part of the icon to download the installer
Don't worry about which version of Python to learn, of course you have to learn the latest
After downloading, run its installation file "python-3.7.4.exe":
- Click to enter the "Custom Installation" interface
- Click "Next" directly
- The figure suggests that you check "Add Environment Variables"
- You can pay attention to the installation directory
- Finally click "Install"
Wait a moment, the installation is complete
How to run Python
I know that you can't wait to write a few lines of code right away and feel the excitement of Python, but there are some things you can't ignore, otherwise you will suffer yourself in the future.
Most of the information will teach you, open the command window and type "python" to run. But this time I use another angle to let you understand these things.
If I want to open the system notepad program now, then I should double-click to run the "notepad program" exe, as shown below:
In fact, running Python is the same. During the previous installation, if you remember the installation directory, you can find a python.exe program there:
- After starting, you can enter the code, this is the interactive mode. Don't care
Normally, we don't write code directly in the black interactive command window.
If I use Notepad to write a very simple code:
- I saved this file under the F drive, called "test.py"
If I want Python to execute this code file now, I have to pass in the path of the code file when starting Python to tell him: You need to help execute the code inside .
We start the command window (win+r, enter "cmd", press Enter), enter the following command, and press Enter to execute:
- There is a space in the command divided into 2 parts
- On the left is the path of python.exe
- On the right is the path of the code file
Press Enter to execute the command:
- You can see that the script was successfully executed
This is the process that we usually have to go through to execute scripts. It just means that there are many inconveniences in entering the full path of the Python program on the command line every time. Therefore, we can simplify the command input by setting system environment variables:
- Just type "python" on the left
This is the importance of checking "Add Environment Variables" when installing Python, but now you know that this is not necessary
Install third-party libraries
Just installing Python is not enough, we can use pip to install various third-party libraries very easily.
Open a command window and enter the following command to install pandas:
- pip install pandas
- Press Enter to execute, and the installation will be successful after a while
When you see the command "pip xxx", you should guess that there must be a pip.exe program somewhere in the computer. Yes, go to your Python installation directory, you will see:
Now if you encounter errors such as "Cannot find program" during execution, you should know that it is time to add environment variables
Shortcut play
Sometimes you need to install various third-party libraries such as pandas, and there will be various accidents, so I suggest you install a Python distribution called Anaconda directly. To put it bluntly, it is a built-in Python environment and various necessary third-party libraries And tool installer.
Also search for "anaconda":
- Choose your operating system
- click to download
The installation process is similar to installing Python, so it's no longer wordy.
Update library
Sometimes an updated version of the third-party library is released, and you want to update the third-party library version on your computer. At this time, you still need to use pip. The following are common operating commands, which are all entered and executed in the command window. If you are interested in Python, you can add the teacher's WeChat: abb436574, get a set of learning materials and video courses for free~
The following are the most common commands on the Internet to update a certain library
- pip install --upgrade pandas
However, sometimes the update fails and the original version cannot be used. I suggest you to uninstall first, then install:
- pip uninstall pandas
- pip install pandas
For beginners, it is not suitable to spend too much energy here, this article will stop there
to sum up
How to install Python:
- Python official website to download the installation package
- Download the installation package from Anaconda official website and install the Anaconda environment directly
Knowledge points to know:
- Run the script, actually run the python.exe program
- The meaning of adding environment variables
Use pip to install and update third-party libraries:
- Installation: pip install pandas
- Update: pip install --upgrade pandas
- Uninstall: pip uninstall pandas