Simple use of virtualenv in python, pythonvirtualenv

Source: Internet
Author: User
Tags virtual environment virtualenv

Simple use of virtualenv in python, pythonvirtualenv
What is virtualenv?

Virtualenv can create an independent Python development environment. For example, the current global development environment is python3.6. Now we need to use django1.3 for one project and django1.9 for another project, in this case, you can use virtualenv to create your own python development environment.


Advantages of virtualenv
  • Independent Application Development Environments

  • Environment upgrades do not affect other applications or global python development environments.

  • It can prevent package management confusion and version conflicts in the system.


Install and create a virtual environment
Run the following command in cmd: Make sure that your python installation path has been added to the environment variable C: \> pip install virtualenv

Create a virtual environment:

C: \> virtualenv testenvUsing base prefix 'C: \ python36 'New python executable in c: \ testenv \ Scripts \ python.exe // by default, Installing setuptools, pip, wheel... done.

You can check it in the current directory:


Activate and disable the current Virtual Environment
C: \ testenv \ Scripts> activate // activate (testenv) C: \ testenv \ Scripts> // note that the terminal has changed (testenv) C: \ testenv \ Scripts> deactivate // close the current virtual environment C: \ testenv \ Scripts>


List packages installed in the current Virtual Environment
(testenv) c:\testenv\Scripts>pip3 listpip (9.0.1)setuptools (37.0.0)wheel (0.30.0)

Now you can install the required package in the virtual environment you created.


Virtualenvwrapper

It is an extension package of virtualenv. Do you still remember the above? Virtualenv requires us to activate the virtual environment. Let's take a look at the advantages of virtualenvwrapper.

C: \> pip install virtualenvwrapper-win // install c: \> mkvirtualenv testenv2 // create a virtual environment C: \ Users \ liubin \ Envs is not a directory, creatingUsing base prefix 'C: \ python36 'New python executable in c: \ Users \ liubin \ Envs \ testenv2 \ Scripts \ python.exe // virtualenvwrapper puts the virtual environment in a directory by default Installing setuptools, pip, and wheel... done. (testenv3) c: \ Users \ liubin \ Envs \ testenv2 \ Scripts> workon // view the current virtual environments Pass a name to activate one of the following virtualenvs: ========================================================== ============================================================== testenv2testenv3 (testenv3) c: \ Users \ liubin \ Envs \ testenv2 \ Scripts> workon testenv2 // workon can also be used to switch the virtual environment (testenv2) c: \ Users \ liubin \ Envs \ testenv2 \ Scripts>



Related Article

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.