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

Python virtual environment settings -- windows -- recommended

編輯:Python

 virtualenv Instructions for use


1.. Methods of configuring domestic installation sources , Directly in cmd Just run the following content in the window
pip config --global set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
2. Installing a virtual environment pip install virtualenv
C:\Users\Administrator>pip install virtualenv
3. The directory of the virtual environment is :
G:\pythonCode\virtualenv>
Creating a virtual environment 【 I want to create a python3.8 Virtual environment for , The operation steps are as follows 】
3.1
G:\pythonCode\virtualenv>virtualenv -p D:\Python\python38\python.exe env-py3.8
Parameter description :
-p: The parameter is to specify the location of the interpreter
env-py3.8: Name of the virtual environment created
Activate and exit the virtual environment
4.
4.1 Activate : Enter this directory
G:\pythonCode\virtualenv\env-py3.8\Scripts>
4.2 activate
G:\pythonCode\virtualenv\env-py3.8\Scripts>activate
4.3 Activated state :
(env-py3.8) G:\pythonCode\virtualenv\env-py3.8\Scripts>
4.4. You can install the software package in this virtual environment
Check which packages are currently installed ?
(env-py3.8) G:\pythonCode\virtualenv\env-py3.8\Scripts>pip list
Package Version
---------- -------
pip 22.1.2
setuptools 62.6.0
wheel 0.37.1
4.4.1: Install package :
4.4.1.1 install django:
4.4.1.2: install django Version selection :https://www.djangoproject.com/download/
(env-py3.8) G:\pythonCode\virtualenv\env-py3.8\Scripts>pip install Django==3.1.14
4.4.1.3 Verify installation version “
(env-py3.8) G:\pythonCode\virtualenv\env-py3.8\Scripts>python -m django --version
3.1.14
================
4.5 Exit virtual environment :deactivate.bat
(env-py3.8) G:\pythonCode\virtualenv\env-py3.8\Scripts>deactivate.bat
G:\pythonCode\virtualenv\env-py3.8\Scripts>

  Instance content :


===============================
2. Virtual environment installation and Application django application
django-admin startproject myshop Create project “myshop”
2.1:(env-py3.8) G:\pythonCode\virtualenv\env-py3.8\Scripts>django-admin startproject myshop
2.2 Create an , Entry project “myshop” Catalog , There are “manager.py” file
(env-py3.8) G:\pythonCode\virtualenv\env-py3.8\Scripts\myshop>
2.3 Run application command “python manage.py startapp app1”
(env-py3.8) G:\pythonCode\virtualenv\env-py3.8\Scripts\myshop>python manage.py startapp app1
2.4 Run the application “python manage.py runserver 0.0.0.0:8000”
(env-py3.8) G:\pythonCode\virtualenv\env-py3.8\Scripts\myshop>python manage.py runserver 0.0.0.0:8000
2.5 visit :
http://127.0.0.1:8000/
Being accessible means success
==========================================
3、 ... and . With the editor vscode open , Or you can use another editor such as pycharm It's fine too
3.1vscode-- menu file -- Open folder --shop Folder of the name of the project
Optional content : Sometimes it's not easy to use 【3.2】
************=================************====
3.2 Choice of virtual environment
use first CTRL+shift+p command : Open the command interaction panel , In the command panel, you can enter commands to search ( Both Chinese and English ), And then execute . Various commands can be executed in the naming panel , Including the functions of the editor and the functions provided by the plug-in
Enter the following command in the open command panel :
Python: Select Interpreter
Click to open the directory where you need to use the virtual environment , choice Scripts Directory open , choice Python.exe
You can choose your virtual environment settings , that will do
************=====================
If 3.2 Out-of-service , We are directly in vscode Directly follow cmd Enter the virtual environment and use the corresponding content information


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