virtualenvVirtualenv is a tool. Used to create an isolated python environment.
First, installation
# pip Install virtualenv
Ii. Creating a Python virtual environment
Command: virtualenv [virtual Environment name].
# virtualenv ENV1
After execution, a folder with the same name as the virtual environment is generated locally.
Use the--python parameter to specify the Python version of the virtual environment:
# virtualenv--python=/usr/local/python-2.7.8/bin/python2.7 ENV1
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 toggle Global sitepackages command to control whether the current environment uses global site-packages.
# virtualenv--system-site-packages ENV1
Third, start the virtual environment
Enter the virtual environment directory and start the virtual environment as follows:
[Root@com ~]# CD env1/
[root@com env1]# Source Bin/activate
(ENV1) [Root@com env1]# Python-v
Python 2.7.8
All modules in the future PIP installation will be installed in the virtual environment directory.
Four, exit the virtual environment
#deactivate
VirtualenvwrapperVirtualenvwrapper is a virtualenv extension tool that makes it easy to create, delete, replicate, and switch to different virtual environments.
1. Installation and Configuration
# pip Install Virtualenvwrapper
Create a folder that holds all virtual environments:
# mkdir ~/workspaces
Set the environment variable and add the following two lines to the ~/.BASHRC.
Export Workon_home=~/workspaces
source/usr/bin/virtualenvwrapper.sh #/usr/local/bin/virtualwrapper.sh)
To make the setting take effect:
# source ~/.BASHRC
Mkvirtualenv can use virtualenv parameters, such as--python, to specify the Python version. When you create a virtual environment, you automatically switch to this virtual environment. The virtual Environment directory is in the Workon_home.
(ENV1) [root@com ~]# mkvirtualenv envpy3--python=python3
(ENVPY3) [Root@com ~]#
5. See what packages are installed in your environment: lssitepackages
6. Directory entering the current environment: cdvirtualenv [subdirectory name]
# cdvirtualenv
# pwd
/root/workspaces/env1sudo Easy_install Virtualenvwrapper
# Cdvirtualenv Bin
# pwd
/root/workspaces/env1/bin
Site-packages directory to enter the current environment: cdsitepackages [subdirectory name]
# cdsitepackages
# pwd
/root/workspaces/env1/lib/python2.6/site-packages
# cdsitepackages Pip
# pwd
/root/workspaces/env1/lib/python2.6/site-packages/pip
7. Control whether the environment uses global site-packages:toggleglobalsitepackages
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.