Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new Managing dependencies section, fixed one typo #7617

Merged
merged 6 commits into from
Sep 26, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion docs/python/python-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ For a Data Science focused tutorial with Python, check out our [Data Science sec

## Prerequisites

To successfully complete this tutorial, you need to first setup your Python development environment. Specifically, this tutorial requires:
To successfully complete this tutorial, you need to first set up your Python development environment. Specifically, this tutorial requires:

- [Python 3](/docs/python/python-tutorial.md#install-a-python-interpreter)
- [VS Code](https://code.visualstudio.com/)
Expand Down Expand Up @@ -261,6 +261,34 @@ To install the required packages in your virtual environment, enter the followin

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!
harish-s-developer marked this conversation as resolved.
Show resolved Hide resolved

## Managing dependencies across environments
harish-s-developer marked this conversation as resolved.
Show resolved Hide resolved
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.

Follow these steps to create a `requirements.txt` file:
1. Activate your virtual environment, if you haven’t already.

```bash
source venv/bin/activate # On macOS/Linux
```

```powershell
.\venv\Scripts\activate # On Windows
```

2. Generate the `requirements.txt` file.

```powershell
pip freeze > requirements.txt
```

3. You can now use the `requirements.txt` file to install dependencies in another environment.

```powershell
pip install -r requirements.txt
```
harish-s-developer marked this conversation as resolved.
Show resolved Hide resolved

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.

## Next steps

To learn how to build web apps with popular Python web frameworks, see the following tutorials:
Expand Down