Django framework study (1) - to create a virtual environment

installation

python official website

Create a virtual environment

  1. Avoid excessive install a package environment, causing environmental load slowly
  2. Solve the problem of the coexistence of multiple versions.

DOC command line to create a virtual environment

Check whether the installation of the virtual environment
1.win + r DOC enter the command line: PIP List

2. enter python installation directory Lib folder to view the site-packages

Installation of third-party libraries virtual environment
pip3 install virtualenv

Create a virtual environment
cd to the directory where the virtual environment, and then command: virtualenv + the name of the virtual environment
such as, in my E: created at Python_Project / ENV directory of a virtual environment called DjangoEnv

In the catalog to create a virtual environment

cd to the Scripts virtual environment, and then activate (activate.bat) virtual environment into a virtual environment, then you can in the virtual environment needed to install various library projects. After installation, quit (deactivate.bat) virtual environment
such as: install Django in a virtual environment

The above command line creates a virtual environment projects

Pycharm create a virtual environment

Open Pycharm, select Create Project, select the virtual environment

Parser can see the items used

Can go to the directory where the virtual environment to look and found two ways to create a virtual environment is the same

Virtual environment preparation

The above command line to create a virtual environment, each time using a virtual environment when they are needed cd to the directory virtual environment where too much trouble. So the virtual environment are formulated to facilitate the use of virtual environments.

  1. Installation virtualenvwrapper-win libraries

  2. 设定虚拟环境目录:即准备一个目录专门存放我们创建的虚拟环境
    如:我们准备在E:\Python_Project\Python Project Virtual Environment这个目录专门存放项目的虚拟环境
    然后配制系统环境变量:也就是系统会默认到这个路径

  3. 创建虚拟环境,这里使用命令:mkvirtualenv+虚拟环境名称,创建虚拟环境。创建虚拟环境还是要cd到该目录,因为这个所谓的虚拟环境配制只是为了方便使用虚拟环境,另外使用mkvirtualenv命令创建虚拟环境时,将自动进入创建的虚拟环境中。

使用方法:

  1. workon :列出该路径下所有的虚拟环境
  2. mkvirtualenv 虚拟环境名称 : 创建虚拟环境(就是make virtual environment)
  3. workon 虚拟环境名称 :启动/切换 虚拟环境
  4. deactivate :退出当前虚拟环境
  5. rmvirtualenv 虚拟环境名称 :删除虚拟环境(就是remove virtual environment)

Guess you like

Origin www.cnblogs.com/sakura-d/p/12158585.html