Python learning----Saving a library file with a virtual environment

Source: Internet
Author: User
Tags virtual environment

If you are responsible for multiple Python projects at the same time, or if you want to easily package a project and its associated library files,

Or if you're concerned about possible conflicts between installed libraries, you can install a Python virtual environment to divide and

The rule.

When a Python library is installed without a virtual environment, you are actually installing it globally. This usually requires a tube

Administrator privileges, or as root, this library file is stored for each user on the device and for each project

In the. Fortunately, creating a virtual environment is simple:

$ virtualenv scrapingenv

This creates a new environment called SCRAPINGENV, which you need to activate before using:

$ CD scrapingenv/

$ source Bin/activate

After activating the environment, you will notice that the environment name appears in front of the command prompt, reminding you that you are currently in the virtual ring.

The environment. Any libraries you install later and any programs you execute are running in this environment.

In the new SCRAPINGENV environment, you can install and use BeautifulSoup:

(scrapingenv) ryan$ pip install Beautifulsoup4

(scrapingenv) ryan$ python

> from BS4 import beautifulsoup

>

When you no longer use a library in a virtual environment, you can exit the environment by releasing the command:

(scrapingenv) ryan$ deactivate

ryan$ python

> from BS4 import beautifulsoup

Traceback (most recent):

File "<stdin>", line 1, in <module>

Importerror:no module named ' BS4 '

All the libraries associated with the project are placed in a single virtual environment, and can be easily packaged for the entire environment to occur to other

People. As long as their Python version is the same as yours, your packaged code can be shipped directly through the virtual environment.

No need to install any more libraries.

Python learning----Saving a library file with a virtual environment

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.