Using a requirements.txt file helps you maintain consistency and makes onboarding contributors easier since they can quickly set up their development environment.
Setting Up Your Tools
Begin by opening your preferred code editor and navigating to its Extensions view. In this lesson, we employ tools such as GitHub Copilot, GitHub Copilot Chat, BlackboxAI, and Tabnine. If these extensions are not already installed, search for them in the Extensions marketplace and install them accordingly. Upon installation, GitHub Copilot may prompt you to authenticate via GitHub. These extensions typically appear in the lower left-hand corner of your editor and provide AI-driven code suggestions and chat features, which can greatly enhance your productivity.Example: Flask Application Code Snippet
Consider the following sample code snippet from a Flask application. This snippet demonstrates how to handle update and delete operations within your virtual environment:Creating a Python Virtual Environment
Follow these steps to create and activate your Python virtual environment:-
Navigate to Your Project Directory:
Open your terminal and change the directory to your project folder. In our example, the project is called “image optimizer”. -
Create the Virtual Environment:
Execute the following command to generate a Python virtual environment named “venv”:Using a consistent name like “venv” simplifies project setup and is frequently included in .gitignore files. This command creates a folder named “venv” that houses all the necessary scripts, libraries, and the current Python interpreter (e.g., Python 3.12). Any package you install while the virtual environment is active will reside in this directory. -
Activate the Virtual Environment:
Within the “venv” folder, a directory called “bin” (or “Scripts” on Windows) contains the activation scripts. For Unix-based systems, activate your environment with:Once activated, your terminal prompt will change to show that you are now working within your virtual environment (commonly indicated by a “(venv)” prefix). Since the correct interpreter is now in use, you can simply run “python” instead of “python3”.
If you use a different shell, follow these commands:
- For C shell (csh):
- For Fish shell:
- On Windows (PowerShell):