First, install PythonCan-compile installation,-yum installation
Second, installation virtualenvYum Source installation: Yum Install python-virtualenv virtualenv is actually a python package, so we can install it with Easy_install or PIP. Easy_install installation method: Easy_install virtualenv
Iii. Creating a python virtual environmentCreate a Python virtual environment using the VIRTUALENV command: virtualenv [virtual Environment name]. After Virtualenv Env1 executes, a folder with the same name as the virtual environment is generated locally. If you have a different version of Python installed in your system, you can use the--python parameter to specify the Python version of the virtual environment: virtualenv--python=/usr/local/python27/bin/python ENV1-- No-setuptools measured by default, the virtual environment does not rely on the global site-packages of the system environment. For example, the system environment installed MYSQLDB module, in the virtual environment import MySQLdb will prompt importerror. If you want to rely on a third-party package for your system environment, you can use parameter--system-site-packages. Alternatively, you can use the Virtualenvwrapper toggleglobalsitepackages command to control whether the current environment uses global site-packages. Virtualenv--system-site-packages ENV1
Iv. Starting a virtual environmentEnter the virtual environment directory and start the virtual environment as follows: CD env1/source bin/activate python-v the command line will be preceded by a parenthesis with the name of the virtual environment in parentheses. All modules installed later Easy_install or PIP will be installed in the virtual environment directory.
v. Exiting the virtual environmentExiting the virtual environment: deactivate
VI, using Virtualenvwrapper Virtualenvwrapper is a virtualenv extension tool that makes it easy to create, delete, copy, and switch between different virtual environments. 1. Install Virtualenvwrapper easy_install virtualenvwrapper 2. Create a folder to hold all virtual environments: mkdir py_vm ( Catalog customization) 3. Set the environment variable and add the following two lines to the ~/.bash_profile. EXPORT WORKON_HOME=/HOME/WORK/PY_VM (absolute path) source /usr/bin/virtualenvwrapper.sh then source ~/.bash_ Profile effective, you can use Virtualenvwrapper. 4. Create a virtual Environment: mkvirtualenv [Virtual Environment name] Mkvirtualenv env2 mkvirtualenv env3 Note: mkvirtualenv can use virtualenv parameters, such as--p Ython to specify the Python version. Once the virtual environment is created, it is automatically switched to this virtual environment. The virtual Environment directory is in Workon_home. 5. List all Virtual Environments:lsvirtualenv-b 6. Start/Switch Virtual environment: Workon [Virtual Environment name] 7. Directory to the current environment:cdvirtualenv performed in the environment: CDVI Rtualenv 8. Deleting a virtual Environment: rmvirtualenv [Virtual Environment name] 9.cpvirtualenv replication Environment cpvirtualenv env1 env3 (copy en V1 to env3) 10.lssitepackages list site-packages content in the current environment (execution in the environment) 11.cdsitepackages Clear all third-party packages in the environment
CentOS uses virtualenv to build a standalone Python environment-python virtual environment