Python+Django movie recommendation system construction

Project source: "Practical Recommender Systems; Kim Falk; January 2019"

Source address: Practical Recommender Systems

This blog post only records how to build a movie recommendation system. For details, please refer to building a complete movie recommendation system website from 0.

1. Create a new virtual environment

  • Download the corresponding project from github

  • Open the moviegeek-master folder after downloading, and open Anaconda promp in the folder

conda create -n prs
conda activate prs
  • Install the libraries required by the project. Requirements.txt contains all the dependent libraries and corresponding versions required by the project.

    pip install -r requirements.txt
    

2. Database settings

2.1 Install PostGreSQL

  • In here Download For postgresql correct version of your operating system, then install and run according to the instructions on the download page.

  • Unzip the compressed package and configure environment variables

    Insert picture description here
    Insert picture description here

  • First D:\pgsql, create a folder named data under the pgsql( ) folder (this is the data storage folder of the database)

  • Then create a new file named env.vbs in the pgsql folder and run the script

    on error resume next
    set sysenv=CreateObject("WScript.Shell").Environment("system") 'system environment array
    Path = CreateObject("Scripting.FileSystemObject").GetFolder(".").Path 'add variable
    sysenv("PGHOME")="D:\pgsql"
    sysenv("PGHOST")="localhost"
    sysenv("Path")=sysenv("PGHOME")+"\bin;"+sysenv("Path")
    sysenv("PGLIB")=sysenv("PGHOME")+"\lib"
    sysenv("PGDATA")=sysenv("PGHOME")+"\data"
     
    wscript.echo "PostgreSQL Success"
    
    
  • Enter the bin directory, open a command prompt as an administrator, and run the following command

    # 初始化数据库
    initdb.exe -D D:\pgsql\data -E UTF-8 --locale=chs -U postgres -W
    
    # 启动数据库
    pg_ctl -D D:\pgsql\logfile -l logfile start
    
    # 注册服务
    pg_ctl register -N PostgreSQL -D D:\pgsql\data
    

    Insert picture description here

  • In D:\pgsql\pgAdmin 4\bincase, there is pgAdmin4.exe, double-click to open

2.2 Create a database for MovieGEEK

Use PostGreSQL's management tool pgadmin to create a database. Name it moviegeek. Write down the username and password you used to create the database. From now on, when you change Django settings, this information will be used in two steps

Note that you must first check whether the PostGreSQL service is started before creating the database. If it is not started, you need to start it first, otherwise you cannot connect

Insert picture description here

2.3 Install Python database driver

After the PostGreSQL database is rotated, it is time to use the Python driver, which allows Django to communicate with the database. I recommend using Psycopg . Download here . Please follow the instructions below to install it.

requirements.txtAlready configured in the very beginning

2.4 Configure Django database connection to connect to PostGreSql

If you use PostGreSQL (or other databases), you need to configure a Django database connection for MovieGEEKS, please follow the steps below. If you need more details, please refer to the Django documentation here.

turn on moviegeek-master/prs_project/settings.py

Update the following:

DATABASES = {
    
    
    'default': {
    
    
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'moviegeek',                      
        'USER': 'db_user',
        'PASSWORD': 'db_user_password',
        'HOST': 'db_host',
        'PORT': 'db_port_number',
    }
}

Update the USER, PASSWORD, HOST and PORT fields:

  • USER (db_user): the username created by the MovieGEEK database
  • PASSWORD (db_user_password): the password created by the MovieGEEK database
  • Host (db_host): local host (if it has been installed on a private computer)
  • PORT (db_port_number): 5432 (default port)

For more information, please refer to the Django documentation link

2.5 Create and populate the MovieGEEKS database

  • Create database

    python manage.py makemigrations
    python manage.py migrate --run-syncdb
    
  • Populate the database

    Run the following script to download the dataset from the MovieGEEKS website.

    Warning: Mac users running Python 3.7 or higher need to run this command before populating the database. /Applications/Python\ 3.7/Install\ Certificates.command. More details here and here .

    Process movie information first

    python populate_moviegeek.py
    python populate_ratings.py
    

    Sometimes the connection will report an error, just try a few more times. . . .

3. Apply for TMDB API

You must create an ID with themoviedb.org to use its pictures.

  • Go to https://www.themoviedb.org/account/signup

  • registered

  • Log in, go to your account settings and create an API . You can access the settings by clicking the avatar in the upper right corner (the default is a blue circle with a white logo). Then you will see settings on the left.

    Insert picture description here

  • Create a file named ".prs" in the moviegeek directory

  • Open .prs and add {"themoviedb_apikey":}Remember to delete "<" and ">". After finishing, the content of the file should be similar to {"themoviedb_apikey":"6d88c9a24b1bc9a60b374d3fe2cd92ac"}

4. Start the web server

To start the development server, run the following command:

python manage.py runserver 127.0.0.1:8000

Running the server like this will make the website available http://127.0.0.1:8000

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_24852439/article/details/104314408