Python installation tutorial and environment configuration (with download link)

The first time I come into contact with Python, it may be a crawler or a small partner in the development of information AI. They all say that the Python language is simple, so it is always beneficial to learn more. Let’s install Python from a novice who does not understand Python at all. The series of work records, and the problems encountered will also be written, so that Xiaobai who doesn't understand at all can also get started with the installation and complete the first Hello world code.

Tips in the front row: There is a green version installation package at the end of the article

[Python installation]

Currently, there are two versions of Python, one is version 2.x and the other is version 3.x, these two versions are not compatible. Due to the increasing popularity of 3.x versions, our tutorials will be based on the latest Python 3.9 version.

  1. Go to the official download page of Python: http://www.python.org/download/
    insert image description here
    There are many versions, we choose the latest version 3.9.0
    insert image description here
    and click Run after the download is complete, the installation interface will appear, remember to check
    insert image description here
    this and install it succeeded
    insert image description here

  2. After the successful installation of running Python
    , open the command prompt window (win+R, enter cmd and press Enter), and after typing python, two situations will appear:

    Situation 1:
    insert image description here
    This indicates that the python installation is successful. When you see the prompt >>> , it means that we are already in the Python interactive environment, you can enter any Python code, and you will get the execution result immediately after pressing Enter. Now, enter exit() and press Enter to exit the Python interactive environment (or close the command line window directly).

    Case two: get an error:

    I will not demonstrate here, because I installed it successfully, I will demonstrate it, and use the wrong pythonn instead of python, so that an error message will be prompted.
    insert image description here

    1. Configure environment variables
      This is because Windows will search for python.exe according to the path set by a Path environment variable. If it is not found, an error will be reported. If you omit to check Add Python 3.9 to PATH during installation, you must manually add the path where python.exe is located to Path.
      If you find that you forgot to check or will not set the PATH path, then you reinstall it and remember to check Add Python 3.9 to PATH and it will be ok. (Step 2: Error messages are generally caused by not configuring environment variables)

    2. Steps: Right-click My Computer –> Select Properties –> Select Advanced System Settings –> Select Environment Variables in the lower right corner
      insert image description here

The environment variables mainly include user variables and system variables. The environment variables that need to be set are in these two variables. The
user variable is to use the downloaded program in the cmd command, and write the absolute path of the program to the user variable. use

insert image description here
insert image description here
5. Test output
win+R, enter cmd and press Enter
insert image description here
, enter python and press Enter to enter the python development environment
. insert image description here
It should be noted that parentheses are required to call functions (printing, etc.), otherwise it will prompt you
insert image description here
to add a paragraph of text directly after print to output, you need Enclose text in double or single quotes. Everyone found that in addition to printing text, print can also output various numbers, calculation results, comparison results, etc. You try to print some other things yourself to see which ones succeed and which ones fail, and if you are interested, guess the reason for the failure.
.In
fact, under the python command line, print can be omitted, and the result of each command will be output by default. like this:
insert image description here

[ Install development tools ]

Install the PyCharm tool, which can be downloaded from the Internet. There are many resources, and there are also installation-free versions, which can be used after decompression. What I am demonstrating now is the Pycharm development tool that needs to be installed.
insert image description here
.
insert image description here
. insert image description here
.
insert image description here
. The first time you open pycharm, it will display this. In this way, there will be a venv folder. When creating a new project, the default is to create a virtual environment folder that does not require venv
insert image description here
. Select the second option and set python environment , the default is none ! ! !

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

insert image description here
insert image description here

insert image description here

insert image description here

insert image description here

insert image description here
insert image description here

insert image description here

Plugins for pyCharm

Download of the Chinese plug-in
Because PyCharm is in English, after downloading the Chinese plug-in, it will be displayed in Chinese after restarting. Open
File-
>Settings... a window will pop up
insert image description here
, select "marketplace" and then enter "Chinese" in the input box After that, you can find the Sinicization plug-in, click "install" to download
insert image description here
insert image description here
and click restart
insert image description here
insert image description here

[Using pip]

Suppose I want to install Selenium
The installation of Selenium is very simple and can be done in the following way.

pip install selenium

insert image description here
Enter directly through the command window, without entering the command line of the python environment, and then enter the above statement to install selenium.

After Selenium is installed, python cannot be used directly, it needs to interface with the browser. Here take the Chrome browser as an example. If you want to use Selenium to successfully call the Chrome browser to complete the corresponding operation, you need to drive it through ChromeDriver.

Link: http://npm.taobao.org/mirrors/chromedriver/ or https://chromedriver.storage.googleapis.com/index.html
(the version should be the same as the Google version)

Mine is version 86.0.4240, so you have to download this version

insert image description here
insert image description here
insert image description here
After the download is complete, unzip and copy to the root folder of the python environment
insert image description here
insert image description here

And run chromedriver through the cmd command line, if no error is reported,
insert image description here
the pip version update will be successful

python -m pip install --upgrade pip

Note: The command line in the python environment is not required, but the update is performed using the cmd command line

insert image description here
Finally, if you feel that it is too troublesome, I also provide you with a green version of the installation package to help you install python smoothly in one step!

Guess you like

Origin blog.csdn.net/BlueSocks152/article/details/131002314