Virtualenv for python multi-environment extension
There are many versions of python, and the functions of each version are quite different. In the process of using, we often encounter inconsistencies between the python version that the third-party library depends on and the version of the system. At the same time, because the bottom layer of the system needs to call the current version of python, we cannot change the python version of the system at will. In this case, multiple python versions will coexist.
So python multi-environment management tools came into being, virtualenv and Pyenv. Both Pyenv and virtualenv are python management tools, but the difference is that the former manages the version of python to switch and use different versions, while the latter chooses the market to separate the system environment and other python environments from each other by creating a virtual environment.
(1) deployment
Step 1: install the python-pip and pythondevel packages
Shell > yum install python-pip python-devel-y
Step 2: check the installation environment
/ / make sure that development environment packages such as gcc glibc are installed on the server
Shell > yum install gcc glibc-devel zlib-devel rpm-build openssl-devel-y
/ / Update pip to the latest version
Shell > pip install-- upgrde pip
Step 3: install virtualenv
Shell > pip install virtualenv
Shell > virtualenv-- version # indicates successful installation
16.7.7
(2) use
Shell > virtualenv-- help
Usage: introduction to virtualenv [OPTIONS] DEST_DIR # syntax
Step 1: create a virtual directory
Shell > virtualenv / python/python3.6.6
Step 2: create a virtual working directory
Shell > virtualenv / python/data/sof/virtualpy/
Step 3: load the environment variables through source to change the local environment to the virtual working directory
Shell > virtualenv / python/data/sof/virtualpy/bin/activate
(virtualpy) [root@oy ~] # # switched successfully, not already entered the virtual working directory
Shell > deactivate exit the virtual environment directory