Underlying virtual environment virtualenv

Source: Internet
Author: User
Tags virtual environment virtualenv

Virtualenvvirtualenv description of the underlying virtual environment

Virtualenv is a creation of a standalone Python environment. Virtualenv creates a folder that contains all the required executables for using the Python project.

It can be used alone to replace the pipenv.

VIRTUALENV Installation

Install via PIP:

# pip install virtualenv

Test whether the installation is complete:

# virtualenv --version15.1.0
Combat-Create a virtual environment for your project create a project virtual environment
# mkdir virtual_project# cd virtual_project/# virtualenv my_project

Description?? :

    • Virtualenv My_project will create a folder in the current directory to hold the Python executable file and a copy of the PIP library so that the other packages can be installed. Virtual Environment name (here is My_project) can be arbitrary, if omitted name will put the file in the current directory.
    • This will create a Python copy under the file directory where you run this command, and put it in a folder named My_project
    • You can also choose a Python interpreter (such as python2.7).
# virtualenv -p /usr/bin/python2.7 my_project
Before using a virtual environment, you need to activate

To activate the virtual environment, the command is as follows:

Description?? :

    • The name of the current virtual environment appears on the left side of the prompt (e.g. my_project) [[email protected] virtual_project]#) so that you can see what the currently active virtual environment is.
    • Since then, any packages you have installed with PIP will be placed in the My_project folder, independent of the packages installed by the global Python.
    • Install the package as usual, such as:
pip install requests
If you have temporarily completed your work in a virtual environment, you can deactivate it:
deactivate

So you go back to the system default Python interpreter, including the installed Library page will go back to the default.

Deleting a virtual environment

To delete a virtual environment, you only need to delete the corresponding folder. (For the current example, execute RM-RF my_project).

Virtual Environment Recycling Work

Because Virtualenv also has some inconveniences, because after a while your system may have a lot of virtual environment scattered everywhere, it will let you forget their name or location.

Running virtualenv with the option--no-site-packages will not contain packages that have been installed globally. This helps keep the package list neat in case you need to access it.

# cd /root/virtual_projectvirtualenv --no-site-packages my_projectNew python executable in /root/virtual_project/bin/pythonInstalling setuptools, pip, wheel...done.
Actual combat--"freeze" the currently installed environment pack in order to maintain the consistency of the environment, the state of the current environment pack is the correct choice. To freeze the environment, you can run the following command:
# “冻结” 当前系统中pip安装的环境包# pip freeze > requirements.txt
# “冻结” my_project 项目虚拟环境中pip安装的环境包(my_project) [[email protected] virtual_project]# pip freeze > requ.txt
Deploy environment packages that are consistent with the "Frozen" environment
# pip install -r requirements.txt

Underlying virtual environment virtualenv

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.