Build API with fastAPI
- Set up a virtual environment: Virtual environments help isolate the project's dependencies from your system's Python installation. Open a terminal or command prompt and navigate to the project directory. Then create a new virtual environment by running the following command:
python3 -m venv venv
This command will create a new virtual environment named "venv" in the current directory.
- Activate the virtual environment: Activate the virtual environment to start using it. The commands to activate the virtual environment vary depending on your operating system:
On Windows:
venv\Scripts\activate.bat
On macOS and Linux:
source venv/bin/activate
- Install project dependencies: Once the virtual environment is activated, you can install the required packages. Typically, Python projects include a requirements.txt file listing all the dependencies. Run the following command to install the dependencies specified in the file:
pip3 install -r requirements.txt
- If you add any new dependencies to the project, you can update the requirements.txt file using the following command:
pip3 freeze > requirements.txt
uvicorn main:app --reload --port [port] --host [host]