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.
.gitignore
The 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