程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Vs Code configuring Python development environment

編輯:Python

VS Code It doesn't include Python Of , So first you have to install a Python.

1、 Terminal operation Python

installed python after , We can start writing with any text editing tool python Code , And then in cmd Run code in .

stay VS Code in , Without installing any plug-ins , It can also run python Code .

Create a new one test.py file , Input print('Hello World!').

Click on see -> terminal ( Shortcut key Ctrl + `) Open the terminal , Input python test.py You can run , With the cmd Run in python The code is the same .

2、 install Python plug-in unit

Without installing the plug-in , Click on debugging -> Start debugging ( Shortcut key F5) There's no way to run the code . Will let you choose the environment , And you don't have an environment at all .

stay VS Code The app store ( Shortcut key :Ctrl + Shift + X) Search inside Python plug-in unit , And install . Here's the picture :

Press Ctrl + Shift + P( or F1), Enter in the open input box Python: Select Interpreter Search for , choice Python Parser .

After choosing the parser , We can go straight to VS Code Running in ( Shortcut key Ctrl + F5) Or debugging ( Shortcut key F5)Python Code. .

3、 see 、 Install external library

Python The most powerful is the external library , stay PyCharm in , Can be in Settings View in 、 Search for 、 install . So in VS Code How to install it in ?

As mentioned above , It can run directly at the terminal .py file , Actually , A terminal is a command prompt (cmd), So it's OK to directly input the corresponding command at the terminal .

View the list of installed packages :

pip list
Copy code 

Install external library :

pip install xxx
Copy code 

Be careful : When the machine is installed with more than one Python When it comes to parsers ,pip It may not be installed in the current parser Directory . I tested this many times and found that , It should be related to the order of environment variables , It will be installed in the directory of the top parser in the environment variable .

4、 Code completion tool

VS Code The code completion plug-in in is Visual Studio IntelliCode. Also install through the app store .

Visual Studio IntelliCode It's a set AI Auxiliary function , It can be sensed through context intelligence , The functions of reasoning and execution of code style improve the working efficiency of developers .

IntelliCode Generate recommendations by using machine learning models trained in thousands of common code bases , And it will grow as you write code , To become more accurate . It gives programming advice based on context , Instead of simply recommending by alphabetical order API.

The most important IntelliCode Has supported Python. After the installation , There can be intelligent tips .

5、 Code checker

PyCharm With code checking tools , and VS Code None of them .

5.1、pylint

When you build .py file , When you start writing code , The bottom right corner may jump out of this ( The old version will , The new version will not ):

Pylint It's a Python Code checker . Need to pass through pip install .

Open Settings , Add the following settings :

"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
Copy code 

And then for code that doesn't meet the specification , There will be a wave line hint .

stay VS Code 1.36.1 edition , Seems not to design python.linting.enabled": true It's fine too .

5.2、flake8 and yapf

flake8 By Python An official test aid Python Is the code a standardized tool , Compared with the current high heat Pylint Come on ,Flake8 Flexible inspection rules , Support for integration of additional plug-ins , Extensibility is strong .Flake8 It's the encapsulation of the following three tools :

  • PyFlakes: Static check Python Tools for code logic errors .
  • Pep8: Static check PEP8 Coding style tools .
  • NedBatchelder’s McCabe: Static analysis Python Tools for code complexity .

Official document address :pypi.python.org/pypi/flake8…

yapf Is a code format tool .

adopt pip Install well Flake8 and Yapf after , Configure as follows .

"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.formatting.provider": "yapf",
Copy code 

If installed pylint Words , To set it Enabled = false, Otherwise, you don't have to .

Once installed , We are in the code file (.py) In the right , Choose format document , You can format the code automatically .

Code checking tools are good , But some strict inspections are not in line with our habits , for example flake8 The default maximum number of characters in a line is 79 individual , If the code is too long, the wavy line will be displayed .

79 The character is too short , We can make it longer , Add the following configuration , Set the maximum length to 128 Characters .

"python.linting.flake8Args": ["--max-line-length=128"],

Link to the original text :https://juejin.cn/post/6844903936411828238


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved