Use the python3 -m venv command to create a new virtual environment, if not created before.
You can name the virtual environment directory whatever you like; here, we'll use fastapi-env
python3 -m venv fastapi-envTo start working on this project, first navigate to the project directory and activate the virtual environment:
source fastapi-env/bin/activateinstall the required packages to run a fastapi application, install only if you have created a new Virtual environment:
pip install fastapi uvicornStart the FastAPI server using Uvicorn:
uvicorn main:app --reloadThe application will be available at http://127.0.0.1:8000.
If the FastAPI server is running, stop it by pressing Ctrl+C in the terminal where it is running.
Deactivate the virtual environment by running:
deactivateRemove the virtual environment directory using the rm -rf command. Make sure you are in the parent directory of the virtual environment:
rm -rf fastapi-env