News from this site

 Rental advertising space, please contact the webmaster if you need cooperation


+focus
focused

classification  

no classification

tag  

no tag

date  

2024-11(6)

[Python skill tree] Python installation and environment configuration under Windows/Linux system

posted on 2023-05-07 21:15     read(1082)     comment(0)     like(1)     collect(3)


1 Python installation under Windows system

This installation is mainly for windows development, so it is installed under the windows 10 system.

1.1 python download and install

Python official website : Python Releases for Windows | Python.org

You can find the version you need here and download it, but it is recommended that you do not download the latest version , you know everything. . . After the download is complete, run the installation.

Download the stable version. The specific download version depends on how many bits your computer has. The blogger’s computer is 64-bit, so the installed version is 64-bit 3.7.4 :

  • You can enter " Settings → System → About " to check the system type of your computer. The bloggers are as follows:

  • Find the corresponding version

Contains three installation types:

  • Online installation, that is, download python through the network after executing the installation: Download Windows x86-64 web-based installer
  • exe program installation: Download Windows x86-64 executable installer
  • Unzip the compressed file and install: Download Windows x86-64 embeddable zip file

Generally choose the exe program to install

Download: 32-bit for windows x86, 64-bit for windows x86-64

The following is the downloaded exe installer:

After downloading the exe, double-click the .exe file to enter the software installation interface, select [ customize Installation ] to customize the installation, and check the [ Add Python to PATH ] option to add environment variables (Python 3.7 to the path), which means to add the Python installation path Add to the Path variable of the system environment variable.

Select the Python installation program and installation location, and then click [ Install ], the software will be installed by default, or if you want to change the location of the installation program, click [ Browse ], select the software installation location in the opened window, and click [ Install] after the selection is complete 】.

After that, wait for the progress bar to be full, which may take a long time.

Finally, the Python installation is complete, click [close] to exit the software installation.

1.2 Python environment variable configuration 

Manually add python environment variable process

  • Find the computer, click the right mouse button, click [Properties] in the pop-up options, and then click [Advanced System Configuration]

  • Click [Environment Variables]

  • In the system variable, find Path, double-click, in the opened editing system variable, add an English semicolon at the end, and copy the python software installation path into it.

  •  Search and enter "cmd" or "win + R" and enter cmd to enter the command window, enter " python --version " and press Enter. If the python version appears, the installation is successful

You can enter the "Python" command in the command prompt to start the Python interpreter: After executing the above command, the following window information appears:

Possible situations and solutions that python cannot find after installation:

  • 1. Close cmd first, then reopen it, then enter "python --version" and press Enter, if it works, it means that cmd was opened and installed;
  • 2. Click the downloaded installation package, select repair, and try again according to the prompt;
  • 3. If the python version does not appear, the environment variable should not be set properly. Open the Path variable of the system environment variable to check whether there is a Python directory. If not, manually configure the environment variables.

1.3 VScode uses python

Visual Studio Code (VScode) official website

Select the corresponding version according to your computer system to download

The interface after VScode starts is as shown in the figure below:

image.png

 To use python in VScode, you need to install the python plugin, as follows:

  • Method 1 : First click the image below, and then enter in the search box: Python , as shown in the figure below, click the button in the red box in the picture below to install the plug-in, after clicking, the button in the red box will change to "Installing", wait, Until "Installing" disappears.

  •  Method 2 : Enter in the search box@id:ms-python.python

 After installing python, you need to select the python interpreter . In the VScode interface, press the keyboard shortcut: F1(or Ctrl+ Shift+ P) , and the text box in the red box in the figure below will be displayed on the top of the VScode interface

 Enter Python:Select Interpreterand select in the command bar, as shown in the figure below:

After that, the corresponding python interpreter will appear, as shown below (mainly depends on the version of python installed on your computer and the path where it is installed):

VScode terminal installation library 

 pip list to view all installed libraries:

2 Python installation under Linux system

2.1 python download and install

Python official website: Python Source Releases | Python.org

On Linux/Unix systems, the default python version is generally 2.x, and python3.x can be installed in the /usr/local/python3 directory.

  • If you don't want to download it on the official website, you can also download it in the following ways, but you need to pay attention to modifying the version number you need:
  1. //替换自己需要的版本
  2. export DOWNLOAD_PYTHON_VERSION=3.7.4
  3. wget https://www.python.org/ftp/python/$DOWNLOAD_PYTHON_VERSION/Python-$DOWNLOAD_PYTHON_VERSION.tgz
  • Unpack Python-3.7.4.tgz: tar -zxvf Python-3.7.4.tgz
  • Create an empty folder for storing python3 programs: mkdir /usr/local/python3
  • Execute the configuration file, compile, compile and install
  1. [root@python tools]# cd Python-3.7.4
  2. [root@python Python-3.7.4]# ./configure --prefix=/usr/local/python3
  3. [root@python Python-3.7.4]# make && make install
  • Establish a soft connection
  1. [root@python Python-3.7.4]# ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
  2. [root@python Python-3.7.4]# ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3
  • Verification and testing
  1. [root@python Python-3.7.4]# python3
  2. Python 3.7.4 (default, Jul 20 2018, 09:24:46)
  3. [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> print("hello world!")
  6. hello world!
  7. >>> exit()

2.2 python environment variable configuration

After the installation is complete, you can add the path /usr/local/python3/bin to the environment variable of your own Linux/Unix operating system, so that you can enter the following command through the shell terminal to start Python3.

  1. $ PATH=$PATH:/usr/local/python3/bin/python3 # 设置环境变量
  2. $ python3 --version
  3. Python 3.7.4

2.3 Install pip related dependencies

  • Install pip related dependencies
  1. yum install openssl-devel -y
  2. yum install zlib-devel -y
  • Download and install setuptools
  1. wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
  2. tar -zxvf setuptools-19.6.tar.gz
  3. cd setuptools-19.6
  4. python3 setup.py build
  5. python3 setup.py install
  • install pip3
  1. wget https://github.com/pypa/pip/archive/9.0.1.tar.gz
  2. tar -zvxf 9.0.1.tar.gz
  3. cd pip-9.0.1
  4. python3 setup.py install
  5. pip3 install --upgrade pip #升级pip3
  • Verify and view the pip installation version 
  1. [root@mini Python-3.7.4]# pip3 --version
  2. pip 9.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)

Welcome to the [ python skill tree ] of [ Left Hand の Tomorrow ] , share + follow + comment



Category of website: technical article > Blog

Author:Ineverleft

link:http://www.pythonblackhole.com/blog/article/343/4646cbddd466577c0639/

source:python black hole net

Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.

1 0
collect article
collected

Comment content: (supports up to 255 characters)