Skip to content

Yuvraj960/Flask

Repository files navigation

Learn Flask

Setting Up a Python Virtual Environment

Always create the Python virtual environment in the same directory as the project. This ensures that the virtual environment is not shared between projects. We will use the virtual environment to install the required packages for the project. This ensures that the project is not dependent on system-wide packages.

Creating a Virtual Environment

To create a virtual environment, run the following command in the terminal:

Windows

python -m venv virtual_environment_name

Linux

python3 -m venv virtual_environment_name

Activating the Virtual Environment

To activate the virtual environment, run the following command in the terminal:

Windows

virtual_environment_name\Scripts\activate

Linux

source virtual_environment_name/bin/activate

Managing Dependencies

In JavaScript, there is a file called package.json where all the dependencies of the project are defined. In Python, we use a requirements.txt file to define all the dependencies of the project. This file is used by the pip tool to install all the dependencies.

Simply list the dependencies in the requirements.txt file and run the following command to install them:

pip install -r requirements.txt