[Python Basics] 02. Python environment setup and installation and configuration of PyCharm

1 Python interpreter

Because Python is an interpreted language. When we write Python code, we get the code to include a .pytext file extension. If you want to run the code, you need a Python interpreter to execute the .pyfile. Environment construction is actually installing Python interpreter. There are several types of Python interpreters:

  • CPython
    After we download and install Python from the official Python website, we directly get an official version of the interpreter: CPython. This interpreter was developed in C, so it is called CPython. CPython compiles Python source code into CPython bytecode, which is interpreted and executed by the virtual machine.
  • Jython
    Jython is a Python interpreter running on the Java platform, which can directly compile Python code into Java bytecode for execution. Jython implements Python on the JVM, written in Java. Jython compiles Python source code into JVM bytecode, and the corresponding bytecode is executed by the JVM.
  • IPython
    IPython is an interactive interpreter based on CPython, that is to say, IPython is only enhanced in interactive mode, but the function of executing Python code is exactly the same as CPython. For example, although many domestic browsers have different appearances, the kernel actually calls IE. CPython is used >>>as the prompt, and IPython is used In [序号]:as the prompt.
  • PyPy
    PyPy is another Python interpreter whose goal is speed of execution. PyPy uses JIT technology to dynamically compile Python code (note that it is not an explanation), so it can significantly improve the execution speed of Python code. The vast majority of Python code can be run under PyPy, but some of PyPy and CPython are different, which leads to the same Python code executed under two interpreters may have different results. If your code is to be executed under PyPy, you need to understand the differences between PyPy and CPython.
  • IronPython is
    similar to Jython, except that IronPython is a Python interpreter running on the Microsoft .Net platform, which can directly compile Python code into .Net bytecode.

2 Build a Python environment

1. First enter the website to download: click to open the link (or enter the URL https://www.python.org/) , after entering, as shown below, select the installation package suitable for your system to download. (Note: prefer to choose stable executable files for downloading)
Insert picture description here
Insert picture description here
2. After the download is complete, as shown below:
Insert picture description here
3. Double-click to install, and set according to the area in the circle, remember to check the box.
Insert picture description here
Insert picture description here
Insert picture description here
4. After the installation is complete, you can enter Python (or Python -V) in the command window to check whether the installation is successful.
Insert picture description here
Insert picture description here

3 Use of pip tools

3.1 Introduction to pip

• We all know that python has many third-party libraries or modules. These libraries play different roles for different applications. We will definitely use these modules in actual projects. So how do you import these modules into your own project?
• Python's official PyPi repository provides us with a unified code hosting repository. All third-party libraries and even open source modules written by you can be posted here to let people all over the world share downloads.
• Python has two famous package management tools easy_install and pip. In python 2, easy_install is installed by default, and pip requires us to install it manually. With the improvement of Python version, easy_install has been gradually eliminated, but some older third-party libraries can still only be installed through easy_install. At present, pip has become the mainstream installation tool. Since Python 2> = 2.7.9 or Python 3.4, pip is installed by default.

3.2 Use of pip

At the command line, enter pip and press Enter to see the help description: The
Insert picture description here
commonly used instructions are as follows:

  • View pip version
pip -v
pip --version

Insert picture description here

  • Ordinary installation
pip install SomePackage             
pip install SomePackage==1.0.5       # 指定版本
pip install 'SomePackage>=1.0.6'     # 最小版本

可以通过使用==, >=, <=, >, < 来限定一个版本的范围

  • Specified version installation
pip install robotframework==2.8.7
  • Uninstall installed libraries
pip uninstall requests
  • List installed libraries
pip list
  • Display information about all installation packages
pip show package
  • Save the list of installed libraries to a local file
pip freeze > D:\桌面\install.txt

Insert picture description here

3.3 Installation using wheel files

In addition to using the above method for network installation, you can also download the installation package, which is a wheel format file, to the local, and then use pip to install.The installation of pip in Python is very convenient, but sometimes you will encounter the problem of installation failure. This can download the wheel file to the local, and then pip to install. When downloading the wheel file, you must check the python version in advance, select the library corresponding to the python version to download. Next, take the installation numpy库as an example. (The download address of the wheel file: https://www.lfd.uci.edu/~gohlke/pythonlibs/ )
Insert picture description here
1. Install the wheel
Insert picture description here
2. Execute the command (the absolute path and file name of the pip install + wheel file include the suffix)
Insert picture description here
3. The installation is complete
Insert picture description here

4 Installation and configuration of integrated development environment

Integrated development environment (IDE, Integrated Development Environment) is to integrate various development-related environments (and tools) together. Pythone's own IDLE or Python Shell to write Python is very suitable for simple programs, but these tools often turn large programming projects into a "pit" full of despair and frustration. So it is very necessary for us to choose an integrated development environment or even a good dedicated code editor. Here are the 10 best Python integrated development environments (IDEs) recommended . This article takes PyCharm as an example for installation.

4.1 Installation of PyCharm

1. First enter the Pycharm official website (or enter the URL https://www.jetbrains.com/pycharm/download/#section=windows ), download the PyCharm installation package, and choose according to your computer's operating system. As an example.
Insert picture description here
2. After the download is complete, as shown below:
Insert picture description here
3. Double-click the downloaded installation package to install it, and then the interface will pop up:
Insert picture description here
4. Select the installation directory, it is recommended to install it on the D drive or E drive, not recommended to be placed on the system disk C Disk:
Insert picture description here
5. Click Next to enter the interface as shown in the figure below, and check according to the figure below:
Insert picture description here
Among them, Create Desktop Shortcut is to create a desktop shortcut. Check whether Create Associations is associated with the file, choose to open the .py file in the future and it will be opened with PyCharm.
6. Click Next to enter the following figure: the
Insert picture description here
default installation is sufficient, click Install directly.
7. After waiting for a few minutes, you will get the following interface to complete the installation:
Insert picture description here
Click Finish, PyCharm installation is complete.

4.2 PyCharm configuration

1. Theme modification File–settings–apperance–theme
2. Code font modification File–settings–Editor-Font
3. Close update File–settings—apperance—System Settings —Updates — Automatically check updates for uncheck
4. Shortcut keys to modify File –Settings—apperance-- Keymap Choose the shortcut key you are accustomed to
5. Automatically guide package File–settings—apperance–General —Auto Import check
6. Open the last project hex File–settings—apperance—System Settings —Reopen last project startup
7. Modify the header of the newly created file File–settings–Editor—Code Style — File and Code Templates — Python Script

 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 # @Time    : ${DATE} ${TIME}
 # @Author  : Jerry
 # @File    : ${NAME}.py
 # @Software: ${PRODUCT_NAME}

8. Modify the font encoding File–settings–Editor—Code Style — File Encoding — Project Encoding

Recommended reading:
[Python basics] 03. Basic concepts (expressions, statements, etc.) and identifiers and keywords
[Python basics] 01. Introduction to Python
  Basic knowledge of computer and programming

 

To be continued ...

Published 5 original articles · praised 3 · visits 319

Guess you like

Origin blog.csdn.net/qq_37572548/article/details/105358066