Git help documents ignore some files--Ignore Python Virtual Environment folder

Source: Internet
Author: User
Tags glob virtual environment

Preface :

To avoid conflicts between installation libraries under multiple Python projects, or to easily package a project, it is recommended that you install a Python virtual environment under each project folder and operate within a virtual environment, after which any libraries you install and any programs you execute are running in this environment. However, when you use Git for versioning, you need to ignore the virtual environment-related files and instead create a requirement.txt document that records the extremely precise version numbers of all dependent libraries, so that you can deploy the running environment elsewhere. These things are best done when you create a new git repository.

Next, there are two things to do: One, create a .gitignore file named, list the file patterns to ignore, and create a requirement.txt document to record the third-party libraries installed in the virtual environment.

Description

python2.x or python3.x, virtualenv installed

1. Use the Vim or VI command to create a file under the project file .gitignore

$ vim. Gitignore

In edit mode, type the I key to start the following characters before the current cursor:

# Virtual Environmentvenv

Where, #用以注释, Venv is the name of the virtual environment, and then type the ESC key, followed by:, W, Q to save and exit. This way, the contents of Venv folders and folders are not included in Git management.

.gitignoreThe format specification for the file is as follows:

  • All empty lines or lines that begin with an annotation symbol are ignored by Git.
  • You can use the standard glob pattern matching.
  • The match pattern / is followed by a backslash () to indicate that the directory is to be ignored.
  • to ignore files or directories other than the specified pattern, you can reverse the exclamation point () before the pattern ! .

The so-called glob pattern refers to the simplified regular expression used by the shell. The asterisk ( * ) matches 0 or more arbitrary characters, and [abc] matches any character in square brackets (this example either matches a, matches a B, or matches a C); The question mark ( ? ) matches only one arbitrary character, and if you use dashes to separate two characters in square brackets, Indicates that all of the two character ranges can be matched (for example, [0-9] to match all numbers from 0 to 9).

SOURCE git Help document: https://git-scm.com/book/zh/v1/git-Basics-Record every update to warehouse

2. Automatically generate Requirements.txt files using pip

(venv) $ pip freeze>requirements.txt

When the command finishes executing, a file named Requirements.txt is generated under the project folder.

Git help documents ignore some files--Ignore Python Virtual Environment folder

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.