- Python - Programming Language, version 3.12
- PostgreSQL Open-source relational database management system, version 15.
- Django - High-level Python web framework
- Django Rest Framework - Powerful and flexible toolkit for building Web APIs
- Pydantic - Data validation
This project requires Python (preferably version 3.12) and the latest PostgreSQL. To check if they are available on your machine, try running the following commands.
It is recommended to install the latest version using Homebrew, although macOS often comes with Python pre-installed.
-
Install Homebrew (if not already installed):
Homebrew is a package manager for macOS that simplifies installing and managing software.
Open Terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Install Python (if not already installed):
brew install [email protected]
Python is typically pre-installed on most Linux distributions. However, we need 3.12 version, follow these steps.
-
Update the Package List:
For Debian-based distributions (e.g., Ubuntu), run:
sudo apt update
-
Install Python:
sudo apt install python3.12 python3.12-venv
-
Download Python Installer:
Visit the official Python website and download the Python 3.12 installer for Windows:
-
Run the Installer:
- Open the downloaded file.
- Ensure that the option "Add Python to PATH" is checked.
- Select "Install Now" and follow the prompts.
Regardless of your operating system, verify that Python has been installed correctly by running:
python3 --version
Or on Windows (if Python 3 is the default):
python --version
You should see the installed version number, e.g.:
Python 3.12
-
Install Homebrew (if not already installed):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Install PostgreSQL:
brew install postgresql
-
Start PostgreSQL:
brew services start postgresql
-
Verify the installation:
psql --version
-
Update the package list:
sudo apt update
-
Install PostgreSQL:
sudo apt install postgresql postgresql-contrib
-
Start PostgreSQL:
sudo systemctl start postgresql
-
Verify the installation:
psql --version
-
Download the PostgreSQL installer from EnterpriseDB.
-
Run the installer and follow the on-screen instructions. Make sure to note down the username (
postgres
) and password during installation. -
After installation, the PostgreSQL service should start automatically. If not, you can start it manually:
- Go to Start > PostgreSQL > Start PostgreSQL.
-
Verify the installation:
Open the command prompt and run:
psql --version
-
Clone the repository:
git clone https://github.com/snbby/MyFood.git cd myfood
-
Create a virtual environment:
python -m venv .venv
-
Activate the virtual environment:
source .venv/bin/activate
.venv\Scripts\activate
-
Install the required packages:
pip install -r requirements.txt
-
Access PostgreSQL, create postgres database, user and password, exit
postgres psql CREATE DATABASE your_db_name; CREATE USER your_db_user_name WITH PASSWORD 'your_db_password'; GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser; \q
-
Set the following values to your environment variables.
Do not forget about
MYFOOD_DEBUG=True
variable. You can choose the language to your taste. Print them in your terminal session:export MYFOOD_DATABASE_NAME=your_db_name export MYFOOD_DATABASE_USER=your_db_user_name export MYFOOD_DATABASE_PASS=your_db_password export MYFOOD_DEBUG=True export MYFOOD_LANGUAGE=en-US
Alternatively, you can create a shell script (set_env.sh), which is more convenient to use each time rather than manually printing environment variables in the terminal every time you need it.
# Set environment variables export MYFOOD_DATABASE_NAME=your_db_name export MYFOOD_DATABASE_USER=your_db_user_name export MYFOOD_DATABASE_PASS=your_db_password export MYFOOD_DEBUG=True export MYFOOD_LANGUAGE=en-US # Print to verify echo "Environment variables set:" echo "Database Name: $MYFOOD_DATABASE_NAME" echo "Database User: $MYFOOD_DATABASE_USER" echo "Database Password: $MYFOOD_DATABASE_PASS" echo "Debug Mode: $MYFOOD_DEBUG" echo "Language: $MYFOOD_LANGUAGE"
Make the script executable:
chmod +x set_env.sh
Run the script:
source ./set_env.sh
-
Apply migrations:
python manage.py migrate
They stored at
myfood/migrations/
-
Create superuser in Django:
python manage.py createsuperuser
-
You will be prompted to enter the following details:
- Username: The desired username for the superuser.
- Email address: The email address of the superuser.
- Password: Your chosen password (you will be asked to confirm it).
Once you have entered the details, Django will create the superuser account.
-
Run the server:
python manage.py runserver
-
Log into the Django admin interface
Log into the Django admin interface at http://127.0.0.1:8000/admin/
using the superuser credentials.
-
Download data dump of all food: On Linux is wget(it is preinstalled)
wget -O eng_products.csv.gz https://static.openfoodfacts.org/data/en.openfoodfacts.org.products.csv.gz
On macOS you should install wget before downloading data dump using brew that was installed before.
brew install wget
On Windows you can install Wget for Windows to perform this command.
-
Unpack it to
artifacts/myfood
You can use
gunzip
on macOS/Linux, it is typically pre-installed.gunzip -c eng_products.csv.gz > artifacts/myfood/eng_products.csv
Use Git Bash for Windows which is installed automatically when you install Git on Windows. Alternatively, you can use 7-Zip on Windows.
-
Be sure that you have set enviromental variables as in Step 6 and 6 of the Project Installation.
-
Activate your virtual enviroment as in Step 3 and 6 of the Project Installation.
-
Migrate database:
python manage.py migrate
-
Launch uploading data to db:
python manage.py food_to_db
-
???
-
Wait approximately 90 minutes...
-
PROFIT!