Skip to content

Latest commit

 

History

History
270 lines (178 loc) · 6.8 KB

install.md

File metadata and controls

270 lines (178 loc) · 6.8 KB

文档尚不完善,如有问题欢迎在 Issue 提出(●゚ω゚●)
不要不好意思,什么问题都可以问,大家都有刚开始的时候嘛

1. 当然是先克隆代码啦

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

🙋提问:这个 git 是什么东西?

如果你不知道 git 是什么,请到此处下载安装。

关于安装的选项,可以自行搜索win/mac 安装 git等字样,找一篇点击量高的博客参考即可。


进入项目文件夹内,复制一份./config_sample.conf文件,改名为./config.conf

2. Python 环境

选择一:开发者流程

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

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

  1. activate the environment

在命令行继续输入: (windows)

activate word

(linux)

source activate word 

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

  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

那么请看这里

  • 如果看到报错提示需要 Visual Studio 依赖

可以考虑参考这位同学的经验。

3. 数据库

二选一即可(小白推荐sqlite

3.1. 选择一:sqlite3

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

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

如果需要直接操作数据库,可以借助 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`
db_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

这里用的是vim编辑器(mac 自带但 windows 不自带的),选择你顺手的编辑器就可以了,不一 定要在命令行操作。

找到下面两行,注释之

#if version < (1, 3, 13):
#    raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required;   you have %s.' % Database.__version__)
  1. 开始背单词!
conda activate <venvName> # 小白流程不用这条命令
python manage.py runserver

打开localhost:8000,开始背单词之旅吧 🤓

当然在此之前你大概需要导入单词数据,那么请看这里


当你想要更新代码的时候,请

git pull
python manage.py makemigrations
python manage.py migrate

更多说明请回到这里查看