MacOS:10.13
安装 pip3
- 下载 get-pip.py:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
- 安装 pip3:
sudo python3 get-pip.py
➜ ~ sudo python3 get-pip.py
The directory '/Users/xufc/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/xufc/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Downloading https://files.pythonhosted.org/packages/62/a1/0d452b6901b0157a0134fd27ba89bf95a857fbda64ba52e1ca2cf61d8412/pip-10.0.0-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 4.6MB/s
Installing collected packages: pip
Found existing installation: pip 10.0.0
Uninstalling pip-10.0.0:
Successfully uninstalled pip-10.0.0
Successfully installed pip-10.0.0
- 几条 pip3 命令
# 查看已安装的库
pip3 list
# 查看已安装的可更新的库
pip3 list --outdated
# 更新已安装的库
pip3 install --upgrade package_name
# 删除已安装的库
pip3 uninstall package_name
安装 Django
- 安装 Django:
pip3 install django
- 查看 Django 版本
➜ ~ django-admin.py --version
2.0.4
安装 MySQL
- 下载 MySQL Server:注意记录安装结束后提示的临时密码
http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg
MySQL DMG - 按照安装向导进行安装
-
重启 MySQL
系统偏好设置
Stop MySQL Server then Start it
- 配置环境变量
➜ ~ sudo mysql --version
sudo: mysql: command not found
➜ ~ export PATH=${PATH}:/usr/local/mysql/bin
➜ ~ mysql --version
mysql Ver 14.14 Distrib 5.7.22, for macos10.13 (x86_64) using EditLine wrapper
- 修改 root 密码
➜ ~ mysqladmin -u root -p password 新密码
Enter password: 临时密码
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
安装 MySQLdb 库
- 安装 mysql-connector-python:
pip3 install mysql-connector-python
- 安装 mysqlclient:
pip3 install mysqlclient
- 检查 MySQLdb 是否安装成功:
python3 -c "import MySQLdb"
没有报错,安装成功
报错1:Library not loaded: libmysqlclient.21.dylib
解决1: https://www.jianshu.com/p/1e1a1cce096b
Django 项目DB配置
MySQL 配置 Local DB:
CREATE DATABASE IF NOT EXISTS test COLLATE utf8_general_ci;
远程 DB 配置见:https://www.jianshu.com/p/c26337253b04更改项目 settings.py 中的 DB 配置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'BugStatis',
'USER': 'root',
'PASSWORD': 'click1',
'HOST': '127.0.0.1',
'PORT': '3306'
}
}