Table of Contents
Preliminary configuration
1. Establish a virtual environment (venv)
2. Configure pip
3. Set up VSC
Home Development Tools VSCode Let's talk about how to configure the python environment in vscode

Let's talk about how to configure the python environment in vscode

Dec 07, 2021 pm 07:02 PM
python vscode

How to configure the python environment in vscode? The following article will introduce to you how to configure the python environment in Visual Studio Code. I hope it will be helpful to you!

Let's talk about how to configure the python environment in vscode

Preliminary configuration

  • Install python (It is recommended to install it directly in the system directory and check Select 'ADD TO PATH' to avoid unnecessary trouble)

  • Install Visual Studio Code (the official website speed is sometimes fast and sometimes slow, it is recommended to download by chance, or use a reliable ladder to download ). [Recommended study: "vscode introductory tutorial"]

  • Check whether python and VSC are installed

    • python: In cmd or Enter python --version in the terminal. If the version number can be output, the installation is successful (the latest version: 3.9.1)
    • pip: python's current mainstream package management tool. In the latest version, pip will be along with python. Install together and complete the system variable settings. Enter pip -V[–version] in cmd or terminal. If the version number can be correctly output, the installation is successful

1. Establish a virtual environment (venv)

The role of venv can be understood as a python environment established for a specific project, which can be understood as a child. When we develop this project, we only need to operate the venv. Problems with the venv will not have an impact on the overall situation. To create venv, you need:

1. Create a folder in the appropriate path (you may wish to set it to venv-demo)

2. Run terminal or cmd in the folder, Enter the following command

python -m venv env

Then a folder named env will be generated under the folder, which is the virtual environment generated for us .

3. Enter the following command in terminal or cmd

Set-ExecutionPolicy -Scope CurrentUser remotesigned

Set the current user to be able to run wps scripts .

You can also run wps as an administrator and remove the -Scope attribute to set all users to be able to run wps scripts (those previously set can ignore step 3)

4. Enter env folder, execute the following command

.\Scripts\activate

to open the virtual environment. Enter exit to exit.

2. Configure pip

Due to well-known reasons, the installation speed of pip without modifying the source of pip in mainland China will be very impressive. So we need to configure pip in the virtual environment.

1. Under the premise of opening the virtual environment, enter pip config debug to check whether there is a corresponding pip configuration file. We only need to create the pip configuration file in the virtual environment.

2. Create the pip.ini file in the env folder

3. Open the pip.ini file and make the following settings:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com
Copy after login

Many commercial companies and universities in China have established pip As for the mirror site, I personally think Alibaba is the best here. Set the index-url and trusted-host respectively, and run pip install [module_name] and the download speed will be acceptable.

3. Set up VSC

  • Open the venv-demo folder with VSC

  • At this time VSC may remind you to install the pylint package, just install it

  • Clickctrl shift p to open the settings panel and searchPython:Select Interpreter option, select python.exe of the virtual environment env as the interpreter

  • At this time clickctrl~Open the terminal, you can see that you have automatically entered the virtual environment of env

  • Create the demo.py file in venv-demo, write anything, and then enter python demo.py in the terminal. It can run normally and the configuration is successful.

For more knowledge about VSCode, please visit: vscode tutorial! !

The above is the detailed content of Let's talk about how to configure the python environment in vscode. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

How to run sublime code python How to run sublime code python Apr 16, 2025 am 08:48 AM

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

How to run python with notepad How to run python with notepad Apr 16, 2025 pm 07:33 PM

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".

Golang vs. Python: Key Differences and Similarities Golang vs. Python: Key Differences and Similarities Apr 17, 2025 am 12:15 AM

Golang and Python each have their own advantages: Golang is suitable for high performance and concurrent programming, while Python is suitable for data science and web development. Golang is known for its concurrency model and efficient performance, while Python is known for its concise syntax and rich library ecosystem.

Golang vs. Python: Performance and Scalability Golang vs. Python: Performance and Scalability Apr 19, 2025 am 12:18 AM

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

Python vs. C  : Learning Curves and Ease of Use Python vs. C : Learning Curves and Ease of Use Apr 19, 2025 am 12:20 AM

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

See all articles