You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -261,6 +261,34 @@ To install the required packages in your virtual environment, enter the followin
261
261
262
262
1. Now, rerun the program, with or without the debugger, to view the output!
263
263
264
+
### Managing dependencies across environments
265
+
When working on Python projects, it’s essential to manage your dependencies effectively. One useful tip is to use the `pip freeze > requirements.txt` command. This command helps you create a `requirements.txt` file that lists all the packages installed in your virtual environment. This file can then be used to recreate the same environment elsewhere.
266
+
267
+
Follow these steps to create a `requirements.txt` file:
268
+
1. Activate your virtual environment, if you haven’t already.
269
+
270
+
```bash
271
+
source venv/bin/activate # On macOS/Linux
272
+
```
273
+
274
+
```powershell
275
+
.\venv\Scripts\activate # On Windows
276
+
```
277
+
278
+
2. Generate the `requirements.txt` file.
279
+
280
+
```powershell
281
+
pip freeze > requirements.txt
282
+
```
283
+
284
+
You can now use the newly generated `requirements.txt` file to install dependencies in another environment. Furthermore, you can continue to add dependencies to it as your project may grow in complexity.
285
+
286
+
```powershell
287
+
pip install -r requirements.txt
288
+
```
289
+
290
+
By following these steps, you ensure that your project dependencies are consistent across different environments, making it easier to collaborate with others and deploy your project.
291
+
264
292
Congrats on completing the Python tutorial! During the course of this tutorial, you learned how to create a Python project, create a virtual environment, run and debug your Python code, and install Python packages. Explore additional resources to learn how to get the most out of Python in Visual Studio Code!
0 commit comments