Second Team Project
The second team project began in earnest today.
This is a project to create a simple SNS service using ‘Django’, which I recently learned.
Implementing the function for the given task doesn’t seem that difficult, but it can be a bit scary because I don’t have any experience coding it.
Our team planned a service to share travel destinations you want to go to.
We plan to post travel destinations that each person wants to visit and implement additional ‘like’ or ‘comment’ functions.
My role here is to sign up, log in, log out.
Today, I first summarized the related content I had previously learned.
And started sharing through ‘github’.
The important point here is about the virtual environment.
If you share the ‘venv’ folder and clone it, a conflict will inevitably occur, so you must manage it with ‘gitignore’.
And by sharing the installed information in ‘requirements.txt’, it helps all team members work in the same virtual environment.
Below is a simple usage guide.
Managing a Python virtual environment (venv
) using a .gitignore
file is a common practice to ensure that virtual environment-related files and directories are not included in your Git repository. This allows for better project portability and avoids polluting your repository with environment-specific data. Here’s how you can manage venv
using .gitignore
:
-
Create a
.gitignore
File:If you don’t already have a
.gitignore
file in your project’s root directory, create one. You can create it manually or by running the following command in your project’s root directory:touch .gitignore
-
Add the Virtual Environment Directory:
Inside your
.gitignore
file, add the line that specifies thevenv
directory. By default, thevenv
directory is created in the project’s root directory:venv/
This tells Git to ignore the entire
venv
directory. -
Optional: Ignore Specific Virtual Environment Files:
If you want to ignore specific files generated by the virtual environment, you can add them to your
.gitignore
file as well. For example, you might want to ignorepyvenv.cfg
orpip-selfcheck.json
. Here’s how you can add them:venv/ pyvenv.cfg pip-selfcheck.json
-
Save and Commit:
Save the
.gitignore
file and commit it to your Git repository:git add .gitignore git commit -m "Add .gitignore to exclude venv"
With these changes, the venv
directory and any specified virtual environment files will be excluded from your Git repository. This means that when you or your collaborators clone the repository or switch to a different branch, you won’t accidentally commit or push your virtual environment, which is typically specific to your local development environment.
To recreate the virtual environment on another machine or for a different developer, you can use the requirements.txt
file to install the project’s dependencies. You can generate this file using the following command within your virtual environment:
pip freeze > requirements.txt
Then, to recreate the virtual environment on another machine, you can use the following command:
python -m venv venv # Create a new virtual environment
source venv/bin/activate # Activate the virtual environment (Linux/Mac)
venv\Scripts\activate # Activate the virtual environment (Windows)
pip install -r requirements.txt # Install project dependencies
This will create a new venv
and install the required packages specified in requirements.txt
.