Home>Article>Development Tools> Let’s talk about how to configure the python environment in vscode
How to configure the python environment invscode? 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!
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
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. Enterexit
to exit.
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, enterpip 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
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 runpip install [module_name]
and the download speed will be acceptable.
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 enterpython 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!