2.2 KiB
2.2 KiB
Quick Start Guide - Python Backend
Step-by-Step Setup
1. Install Python
Make sure you have Python 3.8 or higher installed:
python --version
2. Create Virtual Environment
cd backend
python -m venv venv
3. Activate Virtual Environment
Windows:
.\venv\Scripts\Activate.ps1
Linux/Mac:
source venv/bin/activate
4. Install Dependencies
pip install -r requirements.txt
5. Verify Database Connection
Make sure MySQL is running and the database myapp exists:
CREATE DATABASE IF NOT EXISTS myapp;
6. Run the Server
python start.py
Or:
python app.py
The server should now be running at http://0.0.0.0:3000
Testing the API
Test if the server is working:
curl http://localhost:3000/api/training-projects
Common Issues
ModuleNotFoundError
If you get import errors, make sure you've activated the virtual environment and installed all dependencies.
Database Connection Error
Check that:
- MySQL is running
- Database credentials in
app.pyare correct - Database
myappexists
Port Already in Use
If port 3000 is already in use, modify the port in app.py:
app.run(host='0.0.0.0', port=3001, debug=True)
What Changed from Node.js
- Server Framework: Express.js → Flask
- ORM: Sequelize → SQLAlchemy
- HTTP Client: node-fetch → requests
- Package Manager: npm → pip
- Dependencies: package.json → requirements.txt
- Startup:
node server.js→python app.py
Next Steps
- Test all API endpoints
- Update frontend to point to the new Python backend (if needed)
- Migrate any remaining Node.js-specific logic
- Test file uploads and downloads
- Test YOLOX training functionality
File Structure Comparison
Before (Node.js):
backend/
├── server.js
├── package.json
├── routes/api.js
├── models/*.js
└── services/*.js
After (Python):
backend/
├── app.py
├── requirements.txt
├── routes/api.py
├── models/*.py
└── services/*.py