Skip to content

Files

Latest commit

 

History

History
223 lines (148 loc) · 5.45 KB

install.md

File metadata and controls

223 lines (148 loc) · 5.45 KB

文档尚不完善,如有问题欢迎提 issue 或者私戳我 (●゚ω゚●)

1. 当然是先克隆代码啦

git clone https://github.com/Benature/WordReview.git

然后复制一份项目根目录下的config_sample.py文件,更名为config.py

2. Python 环境

选择一:开发者流程

  1. Install Miniconda (recommanded) or Anaconda at first.
  2. create a virtual environment
    名字随便定,这里以tgword为例
conda create -n tgword python=3

如果你没有其他 django 的项目,偷懒起见可以不创建虚拟环境,以及下面关于虚拟环境的步骤。

  1. activate the environment
source activate tgword 

此时命令行左边应该有显示(tgword)

  1. install requirements
pip install -r requirements.txt

选择二:小白流程

你只要能运行 Python 就好了!

在命令行跑这个👇

pip install django pypugjs pymysql django-compressor django-sass-processor libsass mysqlclient -i http://mirrors.aliyun.com/pypi/simple/ 

另:你可能会遇到的问题

  • pip 命令不见了(像下面这种报错)
pip: command not found

那么请看这里

3. 数据库

二选一即可

3.1. 选择一:sqlite3

config.py文件下,找到下面这个变量,定义为sqlite。(默认就是这个,一般不用动了)

# 使用数据库类型:`mysql`、`sqlite`
database_type = 'sqlite'

不过我是用 MySQL 的,如果想直接操作数据库的话,主要靠你自己百度的,你来问我我也是去百度的。
当然,只要你操作正常,一般没必要去直接操作数据库的。
再其实,就算要直接操作数据库,也可以借助 GUI 工具,工具有哪些可以自己找找看

3.2. 选择二:MySQL

MySQL 操作这么繁琐一看就劝退喽

3.2.1. Install

MacOS

  1. 下载
    download from https://dev.mysql.com/downloads/mysql/, select macOS 10.14 (x86, 64-bit), DMG Archive(.dmg file)

顺路会看到一个叫 workbench 的,可视化工具,就像看 excel 看数据库,which is recommended.

  1. 安装
    clike next all the way.

  2. 设置环境变量

如果mysql -Version命令会报错,补一下环境变量

vim ~/.bash_profile
# 增加以下这行
PATH=$PATH:/usr/local/mysql/bin

Windows 同样在https://dev.mysql.com/downloads/mysql/下载,略。

Ubuntu

# download the configuration
wget https://dev.mysql.com/get/mysql-apt-config_0.8.14-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.14-1_all.deb
# default is fine, select OK and return

sudo apt update
sudo apt-get install mysql-server
# set password(spa2020)
# use strong password encryption

sudo mysql_secure_installation
# enter password
# n (不换root密码)
# Remove anonymous users? : y(删除匿名用户)
# Disallow root login remotely?: n(是否禁止 root 远程登录)
# Remove test database and access to it? : y(删除测试数据库)
# Reload privilege tables now? : y(立即重新加载特权表)

mysql -V # check version
# mysql  Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)

WSL 参见此文

macOS 和 Windows 下可以装个数据库 GUI app

  • MySQL Workbench (free & recommend)
    如同处理 excel,不用学 mysql 命令也能操作数据库啦

3.2.2. Mysql configuration

登录进入 mysql 命令行,密码是安装时候设置的那个。

mysql -uroot -p
show databases;
use mysql;
create database tg_word_db character set utf8;
create user 'tg_word_user'@'localhost' identified by 'tg_word2020'; -- 新建用户
grant all privileges ON tg_word_db.* TO 'tg_word_user'@'localhost'; -- 授权
flush privileges; -- 刷新系统权限表

如果你在这里自定义了数据库名和用户名的话,需要去config.py内修改对应的数据库配置

config.py文件下,找到下面这个变量,定义为mysql。(默认就是这个,一般不用动了)

# 使用数据库类型:`mysql`、`sqlite`
database_type = 'mysql'

4. 前戏

在这个仓库根目录

# 首先确保在虚拟环境下
conda activate tgword # 小白跳过
  1. 数据库迁移
python manage.py makemigrations
python manage.py migrate
  1. 运行 server
python manage.py runserver
  1. debug 🤦‍♂️
    然后大概率会报错👇,因为有个包有问题(实名甩锅)
mysqlclient 1.3.13 or newer is required;

根据自己情况修改/path/to/xxxconda部分,修改文件

vim /path/to/xxxconda/lib/python3.7/site-packages/django/db/backends/mysql/base.py

找到下面两行,注释之

#if version < (1, 3, 13):
#    raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)