Install the virtual environment
System: CentOS 7.2
Python version: Python 2.7.5
1. Introduction to Virtual Environments
A virtual environment is a private copy of the Python interpreter, in which you can install a private package without affecting the global Python interpreter installed on the system
The virtual environment is useful to avoid packet clutter and version conflicts in the system's Python interpreter. For each process
Create a separate virtual environment to ensure that the program can only access packages in the virtual environment, keeping the global interpreter clean
Neat so that it only serves as a source for creating (more) virtual environments. The advantage of using a virtual environment is that you don't need
Administrator privileges.
Virtual environments are created using third-party utility virtualenv. Enter the following command to check if the system is installed
Virtualenv:
$ virtualenv–version
If the results show an error, you will need to install the tool.
CentOS users can install it using the following command:
$sudo yum–y Install Python-virtualenv
Ubuntu users can install it using the following command:
$ sudo apt-get install python-virtualenv
If your computer is a MAC OS X system, you can use Easy_install to install Virtualenv:
$ sudo easy_install virtualenv
If you use Microsoft's Windows system or other operating systems that do not have an official VIRTUALENV package, the installation process is slightly more complicated. Enter the URL https://bitbucket.org/pypa/setuptools in the browser and enter the home page of the Setuptools installer. Find the link to download the installation script on this page, with the name ez_setup.py. Save the file to a temporary folder in your computer, and then execute the following command in this folder:
$ python ez_setup.py
$ Easy_install virtualenv
Attention:
(1). On a Microsoft Windows system, open a command-line window using the Run as Administrator option, and on a UNIX-based system, add sudo to the above two commands, or execute as root. Once the installation is complete, the Virtualenv utility can be called from a regular account.
(2). Python 3.3 natively supports the virtual environment through the Venv module, and the command for PYVENV,PYVENV can
Generation Virtualenv.
The next step is to use the virtualenv command to create a Python virtual environment in the Flasky folder. This command has only one
A required parameter, the name of the virtual environment. After you create a virtual environment, a child file appears in the current folder
folder, the name is the parameter specified in the above command, and the files associated with the virtual environment are saved in this subfolder.
By convention, a generic virtual environment is named Venv:
Now, the Flasky folder has a subfolder named Venv, which holds a completely new virtual environment with a private Python interpreter. Before you can use this virtual environment, you need to "activate" it first.
If you use the Bash command line (Linux and Mac OS X users), you can activate the virtual environment by using the following command:
$ source Venv/bin/activate
If you are using a Microsoft Windows system, the activation command is:
$ venv\scripts\activate
When the virtual environment is activated, the path to the Python interpreter is added to the path, but this change is not permanent
It will only affect the current command line session. To remind you that you have activated the virtual environment, activate the virtual environment
The command modifies the command line prompt and joins the environment name:
(venv) $
When the work in the virtual environment is complete, if you want to go back to the global Python interpreter, you can do so at the command prompt.
Enter Deactivate.
The virtual environment has been built.
1.1. Configure the Python virtual environment