Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure python environment in vscode

2025-03-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces you how to configure the python environment in vscode, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Prophase configuration

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

Install Visual Studio Code (sometimes fast and sometimes slow, it is recommended to download along with the margin, or use a reliable ladder to download). [recommended study: "getting started with vscode"]

Check whether python and VSC are installed

Python: enter python-- version in cmd or terminal. If you can output the version number, it proves that the installation is successful (current latest version: 3.9.1)

Pip: python's current mainstream package management tool. In the latest version, pip will be installed with python and complete the system variable setting. Enter pip-V [- version] in cmd or terminal. If you can output the version number correctly, you will prove that the installation is successful.

First, establish a virtual environment (venv)

The role of venv can be understood as a python environment created for a particular project, or as a child. We only need to operate on the venv when we develop the project, and the problem with venv will not affect the overall situation. To build a venv, you need to:

1. Create a folder under the appropriate path (you might as well set it to venv-demo)

2. Run terminal or cmd under this folder, and enter the following command

Python-m venv env

Then a folder called env is generated under this folder, which is the virtual environment that we generated.

Enter the following command in terminal or cmd

Set-ExecutionPolicy-Scope CurrentUser remotesigned

Sets the current user to run wps scripts.

You can also set all users to run wps scripts by removing the-Scope attribute by running wps as an administrator (step 3 can be ignored as previously set)

4. Enter the env folder and execute the following command

.\ Scripts\ activate

The virtual environment can be opened. Enter exit to exit.

2. Configure pip

For well-known reasons, the install speed of pip's source pip without modification in mainland China can be very touching. So we need to configure pip in the virtual environment.

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

2. Create the pip.ini file under 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

Many commercial companies and universities in China have set up pip mirror stations, and I think Ali is the best among them. If you set up index-url and trusted-host respectively, the download speed of pip install [module_name] will be acceptable.

3. Set VSC

Open the venv-demo folder with VSC

At this point, VSC may remind you to install the pylint package, just install it.

Click ctrl+shift+p to open the settings panel, search for the Python:Select Interpreter option, and select the python.exe of the virtual environment env as the interpreter

When you click ctrl+ ~ to open the terminal, you can see that you have automatically entered the virtual environment of env.

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

On how to configure the python environment in vscode to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report